jamun-is-confused

Well Jamun is very proud of the way he knows everything ( or at least thinks so ).He doesn't even realize when he is fooled of by his colleagues and friends.
Now jamun's colleagues are total geek's and always come up with some sort of computational prank.But this time they try something new.
As Jamun is waving about how they all are wasting their future, they ask him for helping to figure out a problem. The problem is as follows : 

N children's are sitting in a line and everyone has picked up Xi number of sweets from the sweet basket.As all the children's have unequal number of sweets they get jealous of each other and riots come up.Now Jamun's colleagues are given instructions that they have to make things right and that also in a playful way.They have been instructed that in every round of the play they have to pick up any 2 children with unequal sweets , and compare sweets they have.The kid having the larger number of sweets is then given the difference of the two.

For example, if one kid has 2 and the other has 5. Then the kid with 5 sweets is replaced by (5-2)=3 sweets.Now the kids have 2,3 sweets each.

This is done until all children's have equal number of sweets.
Now Jamun and his colleagues being as lazy as they are, want to know what will this final number for which the every kid have equal number of sweets.

(See the Sample Test Cases for Clarification. )

But even this problem proves too hard for them and Jamun asks your help to find out the answer.

Input

The first line of the input contains an integer T, the number of test cases. Then follow the description of T test cases. 
The first line of each test case contains a single integer N, the number of children.
The second line contains N space-separated positive integers, denoting the number of sweets each children has.

Output

For each test case, output a line having a single integer - the final number of sweets each kid has.

Constraints

1 ≤ T ≤ 336

1 ≤ N ≤ 1000

1 ≤ S[i] ≤ 10^9

Problem Setter : Shikhar Singh

SAMPLE INPUT
2
3
5 15 10
3 
3 1 2

SAMPLE OUTPUT
5
1

Explanation

Case 1:

(5,15) are picked-> 15 replaced by (15-5) = 10 -> new configuration 5 10 10
(5,10) are picked-> 10 replaced by (10-5) = 5 -> new configuration 5 10 5
(10,5) are picked-> 10 replaced by (10-5) = 5 -> new configuration 5 5 5

Final answer is 5.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from sys import stdin
from fractions import gcd
from functools import reduce
for i in range(0,int(stdin.readline())):
	a=stdin.readline()
	b=list(map(int,stdin.readline().split()))
	print(reduce(gcd,b))
	


import sys
from fractions import gcd

T = int(sys.stdin.readline())

for i in range(T):
	N = int(sys.stdin.readline())
	x = str(sys.stdin.readline())
	seq = x.split(" ")
	g = int(seq[0])
	for j in range(1,N):
		g = gcd(g,int(seq[j]))
	print(g)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def gcd(a, b):
	while b:
        	a,b=b,a%b
    	return a
for i in range(eval(input())):
	a=eval(input())
	b=list(map(int,input().split()))
	t=b[0]
	for j in range(1,a):
		t=gcd(t,b[j])
	print(t)
		
		


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
The first line of the input contains an integer T, the number of test cases. Then follow the description of T test cases. The first line of each test case contains a single integer N, the number of children. The second line contains N space-separated positive integers, denoting the number of sweets each children has.
'''
from fractions import gcd

T = int(input())

while (T != 0):
	N = int(input())
	lst = list(map(int, input().split()))
	
	ans = gcd(lst[0], lst[1])
	
	for element in lst[2:]:
		ans = gcd(ans, element)
	
	print(ans)
	
	T -= 1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from functools import reduce
def GCD(a,b):
	""" The Euclidean Algorithm """
	a = abs(a)
	b = abs(b)
        while a:
                a, b = b%a, a
        return b
        
        
def GCD_List(list):
	""" Finds the GCD of numbers in a list.
	Input: List of numbers you want to find the GCD of
		E.g. [8, 24, 12]
	Returns: GCD of all numbers
	"""
	return reduce(GCD, list)
	
T=int(input())
for t in range(T):
	N=int(input())
	S=[int(x) for x in input().split()]
	print(GCD_List(S))
	


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

while test:
	test-=1
	n = int(input())
	arr = [int(i) for i in input().split()]
	
	gc = 0
	for i in range(n):
		gc = gcd(gc, arr[i])
	print(gc)


from fractions import gcd
t=int(input())
for x in range(t):
	n=int(input())
	s=input().split(" ")
	res=int(s[0])
	for y in range(n):
		res=gcd(res,int(s[y]))
		if res==1:
			break
	print(res)