There are two integers (X and N). You have to make a number in such a way that it contains the first digit and last digit occurring in X^{1 }, X^{2 }, X^{3},  .... X^{N}.
For Example: let's take  X=12 and N=5.
let l is last digit and f is first digit.
12^{1  }= 12, the first digit of 12 is 1(f1) and last digit is 2 (l1).
12^{2} = 144, the first digit of 144 is 1 (f2) and last digit is 4 (l2).
12^{3} = 1728, the first digit of 1728 is 1 (f3) and last digit is 8  (l3).
12^{4} = 20736, the first digit of 20736 is 2 (f4) and last digit is 6 (l4).
12^{5} = 248832, the first digit of 248832 is 2 (f5) and last digit is 2 (l5).
We made a number in the format f1 l1 f2 l2 f3 l3 f4 l4 f5 l5 .
so number becomes 1214182622.
 
Example 1:
Input:
X = 10, N = 2
Output:
1010
Explanation:
10^{1} = 10. So, f1=1 and l1=0
10^{2} = 100. So, f2=1 and l2=0
Therefore, Output is 1010.
Example 2:
Input:
X = 99, N = 1
Output:
99
Explanation:
99^{1} = 99. So, f1=9 and l1=9
Therefore, Output is 99.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function powerGame() which takes 2 Integers X and N as input and returns the answer.
 
Expected Time Complexity: O(N*(Sum of number of digits in X^{1}, X^{2}..., X^{N}))
Expected Auxiliary Space: O(1)
 
Constraints:
10 <= X <= 100
1 <= N <= 8

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def powerGame(self, X, N):

        # code here 

Solutions:
class Solution:

	def powerGame(self, X, N):
		new_number = ''
		for i in range(1, N + 1):
			number = X ** i
			new_number = new_number + str(number)[0] + str(number)[-1]
		return new_number


import math

class Solution:

	def powerGame(self, X, N):
		(c, l) = ([], [])
		for i in range(1, N + 1):
			c.append(str(pow(X, i)))
		for i in c:
			l.append(i[0] + i[-1])
		return ''.join(l)


class Solution:

	def powerGame(self, n, x):
		k = 1
		s = ''
		for i in range(1, x + 1):
			k = k * n
			b = str(k)
			s += b[0]
			if len(b) > 1:
				s += b[-1]
		return s


class Solution:

	def powerGame(self, X, N):
		result = []
		for i in range(1, N + 1):
			poww = str(pow(X, i))
			result.append(poww[0])
			result.append(poww[-1])
		return ''.join(result)


class Solution:

	def powerGame(self, X, N):
		s = ''
		for i in range(1, N + 1):
			x = str(X ** i)
			s += x[0]
			s += x[-1]
		return s


class Solution:

	def powerGame(self, X, N):
		power = 1
		num = ''
		for i in range(N):
			power *= X
			num = num + str(power)[0] + str(power)[-1]
		return int(num)


class Solution:

	def powerGame(self, X, N):
		p = 1
		t = ''
		for i in range(1, N + 1):
			p = p * X
			d = str(p)
			t += d[0] + d[-1]
		return t


class Solution:

	def powerGame(self, X, N):
		m = ''
		for i in range(1, N + 1):
			m += str(pow(X, i))[0]
			m += str(pow(X, i))[-1]
		return int(m)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, N) = map(int, input().split())
		ob = Solution()
		print(ob.powerGame(X, N))


class Solution:

	def powerGame(self, X, N):
		res = ''
		for itr in range(1, N + 1):
			res += str(X ** itr)[0]
			res += str(X ** itr)[-1]
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, N) = map(int, input().split())
		ob = Solution()
		print(ob.powerGame(X, N))


class Solution:

	def powerGame(self, X, N):
		ans = ''
		for i in range(1, N + 1):
			ans = ans + str(pow(X, i))[0]
			ans = ans + str(pow(X, i))[-1]
		return int(ans)


class Solution:

	def powerGame(self, X, N):
		s1 = ''
		for i in range(1, N + 1):
			a1 = X ** i
			c1 = str(a1)
			s1 += c1[0] + c1[-1]
		return s1


class Solution:

	def powerGame(self, X, N):
		result = []
		for n in range(1, N + 1):
			power_num = str(pow(X, n))
			result.append(power_num[0])
			result.append(power_num[-1])
		return ''.join(result)


import math

class Solution:

	def powerGame(self, X, N):
		m = ''
		for n in range(1, N + 1):
			power_num = str(pow(X, n))
			m += power_num[0]
			m += power_num[-1]
		return m


class Solution:

	def powerGame(self, X, N):
		l = []
		s = ''
		for i in range(1, N + 1):
			a = str(X ** i)
			b = str(a)
			b = b[::-1]
			l.append(a)
			s += a[0] + b[0]
		return s


class Solution:

	def powerGame(self, X, N):
		stri = ''
		for j in range(1, N + 1):
			num = str(X ** j)
			stri += num[0] + num[-1]
		return stri


class Solution:

	def powerGame(self, X, N):
		s = ''
		for i in range(1, N + 1):
			m = pow(X, i)
			l = list(str(m))
			s += l[0] + l[len(l) - 1]
		return int(s)


class Solution:

	def powerGame(self, X, N):
		s = ''
		for i in range(1, N + 1):
			a = X ** i
			l = list(str(a))
			s += str(l[0]) + str(l[len(l) - 1])
		return s


class Solution:

	def powerGame(self, X, N):
		d = ''
		for i in range(1, N + 1):
			don = ''
			res = 0
			res = X ** i
			res = str(res)
			don = str(res[0]) + str(res[len(res) - 1])
			d += don
		return int(d)