Jack is very fond of reading. He reads a lot many pages of books in a day. Since he is obsessed with reading, he reads K times more pages than the number of pages he read the previous day.He read 1 page on the first day. He wants to see that on any given day N, how many pages will he read.Since the answer can be very large, find the answer in modulo 10^{9}+7.
Example 1:
Input: N = 5, K = 2 
Output: 16 
Explanation: 
On Day 1 : 1
On Day 2 : 2
On Day 3 : 4
On Day 4 : 8
On Day 5 : 16
So the answer is 16. 
Example 2:
Input: N = 2, K = 3 
Output: 3
Explanation: 
On Day 1 : 1
On Day 2 : 3
So the answer is 3. 
Your Task:  
You dont need to read input or print anything. Complete the function nthDayPage() which takes N and K as input parameter and returns the answer.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=10^{6}
1<= K <=10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def nthDayPage (self, N, K):
        # code here 

Solutions:
class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		x = K ** N
		x = x % 1000000007
		return x


class Solution:

	def nthDayPage(self, N, K):
		return K ** (N - 1) % (10 ** 9 + 7)


class Solution:

	def nthDayPage(self, N, K):
		l = [1]
		for i in range(N):
			l.append(l[-1] * K % (10 ** 9 + 7))
		return l[N - 1]


import math

class Solution:

	def nthDayPage(self, N, K):
		if N == 1:
			return 1
		m = int(1000000000.0) + 7
		(p, x, res) = (N - 1, K, 1)
		while p != 0:
			if p % 2 != 0:
				res = res * x
			x = x * x
			p = p >> 1
		return res % m


class Solution:

	def nthDayPage(self, N, K):
		self.s = 1
		for i in range(2, N + 1):
			self.s *= K
		return self.s % (10 ** 9 + 7)


class Solution:

	def nthDayPage(self, N: int, K: int) -> int:
		return K ** (N - 1) % 1000000007


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		X = K ** N
		X = X % 1000000007
		return X


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		y = K ** N
		y = y % 1000000007
		return y


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		a = K ** N
		a = a % 1000000007
		return a


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		s = K ** N
		s = s % 1000000007
		return s


class Solution:

	def nthDayPage(self, N, K):
		if N == 1:
			return 1
		else:
			return K ** (N - 1) % 1000000007


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		m = K ** N
		m = m % 1000000007
		return m


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		x = K ** N
		x = x % 1000000007
		return x
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, K) = input().split(' ')
		N = int(N)
		K = int(K)
		ob = Solution()
		print(ob.nthDayPage(N, K))


from math import *

class Solution:

	def nthDayPage(self, N, K):
		if N == 1:
			return 1
		else:
			return K ** (N - 1) % 1000000007
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, K) = input().split(' ')
		N = int(N)
		K = int(K)
		ob = Solution()
		print(ob.nthDayPage(N, K))


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		res = K ** N
		res = res % (10 ** 9 + 7)
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, K) = input().split(' ')
		N = int(N)
		K = int(K)
		ob = Solution()
		print(ob.nthDayPage(N, K))


from math import pow

class Solution:

	def nthDayPage(self, N, K):
		return int(K ** (N - 1) % (10 ** 9 + 7))
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, K) = input().split(' ')
		N = int(N)
		K = int(K)
		ob = Solution()
		print(ob.nthDayPage(N, K))


class Solution:

	def nthDayPage(self, N, K):
		return pow(K, N - 1) % 1000000007


class Solution:

	def nthDayPage(self, N, K):
		N = N - 1
		z = K ** N
		z = z % 1000000007
		return z