Given two function, one is h(x) which is the product of all the number in an array A[ ] having size N and another
function f(x) which denotes the GCD of all the numbers in an array. Your task is to find the value of  h(x)^{f(x)}.
Note: Since the answer can be very large, use modulo 10^{9}+7.
Example 1:
Input:
N = 2, A[] = {2, 4}
Output:
64
Explanation:
h(x) = 8, f(x) = 2, Therefore, the
answer is 8^{2} = 64.
Example 2:
Input:
N = 3, A[] = {1, 3, 7}
Output:
21
Explanation:
h(x) = 21, f(x) = 1, Therefore, the
answer is 21^{1} = 21.
Your Task:
You don't need to read input or print anything. Your task is to complete the function getVal() which takes an Integer N and an array of integers A[] as input and returns the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{5}
1 <= A[i] <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def getVal(self, N, A):
        # code here 

Solutions:
class Solution:

	def getVal(self, N, A):
		m = 1000000007

		def gcd(a, b):
			if a == 0:
				return b
			return gcd(b % a, a)
		multiple = 1
		for i in A:
			multiple = multiple * i % m
		g = A[0]
		for i in A[1:]:
			g = gcd(i, g)
		return pow(multiple, g) % m


M = 10 ** 9 + 7

class Solution:

	def getVal(self, N, A):
		gcd = get_gcdofArray(A, N)
		product = get_product(A, N)
		return product ** gcd % M

def get_product(A, N):
	re = A[0] % M
	for i in range(1, N):
		re = re * (A[i] % M) % M
	return re

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def get_gcdofArray(A, N):
	result = A[0]
	for i in range(1, N):
		result = gcd(result, A[i])
	return result


from functools import reduce

class Solution:

	def getVal(self, N, A):
		mod = 10 ** 9 + 7
		gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
		h = reduce(lambda x, y: x * y % mod, A)
		f = reduce(gcd, A)
		return h ** f % mod


from functools import reduce

class Solution:

	def gcd(self, a, b):
		while b:
			(a, b) = (b, a % b)
		return a

	def gcds(self, n, arr):
		numb = iter(arr)
		if n == 1:
			return next(numb)
		result = self.gcd(next(numb), next(numb))
		for n in numb:
			result = self.gcd(result, n)
		return result

	def getVal(self, N, A):
		return reduce(lambda x, y: x * y % (10 ** 9 + 7), A, 1) ** self.gcds(N, A)


from math import gcd

class Solution:

	def getVal(self, N, A):
		ans = 1
		cnt = A[0]
		for i in A:
			ans = ans * i % 1000000007
			cnt = gcd(i, cnt)
		return ans ** cnt


from math import *

class Solution:

	def getVal(self, N, A):
		g = A[0]
		h = 1
		for i in range(len(A)):
			h = h * A[i] % (10 ** 9 + 7)
			g = gcd(A[i], g)
		return h ** g


from math import *

class Solution:

	def getVal(self, N, A):
		g = A[0]
		h = 1
		for i in range(len(A)):
			h = h * A[i] % (10 ** 9 + 7)
			g = gcd(A[i], g)
		return h ** g
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		ob = Solution()
		print(ob.getVal(N, A))


def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

class Solution:

	def getVal(self, n, a):
		s = 1
		res = a[0]
		for i in a:
			s = s * i % (1000000000.0 + 7)
			res = find_gcd(res, i)
		return int(s ** res % (1000000000.0 + 7))
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		ob = Solution()
		print(ob.getVal(N, A))


class Solution:

	def getVal(self, N, A):
		if N == 0:
			return 0
		if N == 1:
			return pow(A[0], A[0])

		def gcd(a, b):
			while a:
				(a, b) = (b % a, a)
			return b
		g = gcd(A[0], A[1])
		x = 1
		for i in range(len(A)):
			g = gcd(g, A[i])
			x = x * A[i] % 1000000007
		return pow(x, g) % 1000000007


class Solution:

	def gcd(self, a, b):
		while b:
			(a, b) = (b, a % b)
		return a

	def power(self, x, y, p):
		res = 1
		if x == 0:
			return 0
		x = x % p
		while y > 0:
			if y & 1:
				res = res * x % p
			y = y >> 1
			x = x * x % p
		return res

	def getVal(self, N, A):
		prod = 1
		for i in A:
			prod = prod * i % 1000000007
		prev = A[0]
		for i in range(1, len(A)):
			prev = self.gcd(prev, A[i])
		return self.power(prod, prev, 1000000007)


class Solution:

	def getVal(self, N, A):
		mul = A[0]
		ans = A[0]
		for i in range(1, N):
			mul = mul * A[i] % 1000000007
			(a, b) = (ans, A[i])
			while b != 0:
				(a, b) = (b, a % b)
			ans = a
		return mul ** ans % 1000000007


def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

class Solution:

	def getVal(self, N, A):
		h = 1
		g = 0
		for i in A:
			h = h * i % 1000000007
			g = gcd(g, i)
		return h ** g


def getgcd(a, b):
	if a == 0 or b == 0:
		return a + b
	if a == b:
		return a
	if a > b:
		return getgcd(a % b, b)
	if a < b:
		return getgcd(b % a, a)

class Solution:

	def getVal(self, N, A):
		A_prod = 1
		for i in range(len(A)):
			A_prod = A_prod * A[i]
			if A_prod >= 10 ** 9 + 7:
				A_prod = A_prod % (10 ** 9 + 7)
		if N == 1:
			fx = A[0]
			ans = 1
			for i in range(fx):
				ans = A_prod * ans
				if ans >= 10 ** 9 + 7:
					ans = ans % (10 ** 9 + 7)
			return ans
		num = A[0]
		for i in range(len(A) - 1):
			num = getgcd(num, A[i + 1])
		ans = 1
		for i in range(num):
			ans = ans * A_prod
			if ans >= 10 ** 9 + 7:
				ans = ans % (10 ** 9 + 7)
		return ans


class Solution:

	def getVal(self, N, A):

		def gcd(a, b):
			if b % a == 0:
				return a
			return gcd(b % a, a)
		product = 1
		k = 0
		m = 1000000007
		for i in range(1, N):
			if k == 0:
				k = gcd(A[i - 1], A[i])
			else:
				k = gcd(k, A[i])
		for i in A:
			product = product * i % m
		if N == 1:
			return product ** A[0]
		return product ** k


from math import pow

class Solution:

	def gcd(self, a, b):
		return a if b == 0 else self.gcd(b, a % b)

	def getVal(self, n, A):
		if n == 1:
			return A[0] * A[0]
		MOD = 1000000007
		gcd = self.gcd(A[0], A[1])
		prod = A[0] * A[1] % MOD
		for i in range(2, len(A)):
			prod = prod * A[i] % MOD
			gcd = self.gcd(gcd, A[i])
		return int(pow(prod, gcd)) % MOD


class Solution:

	def getVal(self, N, A):
		h = self.h_(N, A) % (10 ** 9 + 7)
		f = self.f(N, A) % (10 ** 9 + 7)
		return h ** f % (10 ** 9 + 7)

	def h(self, N, A):
		if N == 1:
			return A[0]
		return A[0] * self.h(N - 1, A[1:])

	def h_(self, N, A):
		total = A[0]
		for i in range(1, N):
			total = total * A[i] % (10 ** 9 + 7)
		return total

	def f(self, N, x):
		gcd = x[0]
		if N == 1:
			return gcd
		for i in range(1, N):
			gcd = self._get_gcd(gcd, x[i])
		return gcd

	def _get_gcd(self, a, b):
		if b == 0:
			return a
		return self._get_gcd(b, a % b)


class Solution:

	def getVal(self, N, A):

		def gcd(a, b):
			if b == 0:
				return a
			else:
				return gcd(b, a % b)
		if len(A) == 1:
			return A[0] * A[0] % 1000000007
		res = 0
		w = 1
		for i in range(N):
			res = gcd(res, A[i])
			w = w * A[i]
			w = w % (10 ** 9 + 7)
		c = w ** res % (10 ** 9 + 7)
		return c


class Solution:

	def big_pow(self, x, n, mod):
		if n == 0:
			return 1
		z = self.big_pow(x, n // 2, mod)
		if n % 2 == 1:
			return (z * z * x + mod) % mod
		return (z * z + mod) % mod

	def gcd(self, a, b):
		return a if b == 0 else self.gcd(b, a % b)

	def getVal(self, N, A):
		cd = A[0]
		pr = 1
		for x in A:
			cd = self.gcd(cd, x) % 1000000007
			pr = pr * x % 1000000007
		return self.big_pow(pr, cd, 1000000007)


class Solution:

	def getVal(self, N, A):

		def gcdFunction(greater, smaller):
			if smaller == 0:
				return greater
			return gcdFunction(smaller, greater % smaller)
		gcd = 0
		product = 1
		for i in range(len(A)):
			gcd = gcdFunction(max(gcd, A[i]), min(gcd, A[i]))
			product *= A[i]
			product %= 10 ** 9 + 7
		return product ** gcd % (10 ** 9 + 7)