John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1, and having the following property:

GCD(B[i], B[i+1]) = A[i],  ∀ 1  ≤ i  ≤ N

As there can be many such lists, John wants to know the list B in which sum of all elements is minimum. It is guaranteed that such a list will always exist.

Input Format 

The first line contains an integer T, i.e., the number of the test cases. T testcases follow. 

The first line of each test case contains an integer N, i.e., the number of elements in the array. 

The second line of each test case contains N space separated integers that  denote the elements of the list A.  

Output Format 

For each test case, print in a new line the list B such that each element is separated by a single space. 

Constraints 

1 ≤ T ≤ 10 

2 ≤ N ≤ 10^{3} 

1 ≤ A[i] ≤ 10^{4} 

1 ≤ B[i]  

Sample Input  

2
3
1 2 3
3
5 10 5

Sample Output  

1 2 6 3
5 10 10 5

Explanation  

For the first testcase, 

 GCD(1,2) = 1
 GCD(2,6) = 2
 GCD(6,3) = 3
 sum = 1+2+6+3 = 12 which is minimum among all possible list B

For the second testcase, 

GCD(5, 10) = 5
GCD(10, 10) = 10
GCD(10, 5) = 5
sum = 5 + 10 + 10 + 5 = 30 which is the minimum among all possible list B

Difficulty: EASY
Tags: Number theory

Starter code:

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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	(a, ret) = ([1] + list(map(int, input().split())) + [1], '')
	for i in range(1, n + 2):
		ret += str(lcm(a[i], a[i - 1])) + ' '
	print(ret)


import fractions

def lcm(a, b):
	return int(a * b / fractions.gcd(a, b))
tcs = int(input())
for tc in range(tcs):
	num = int(input())
	ints = list(map(int, input().split(' ')))
	string = str(ints[0]) + ' '
	for i in range(0, len(ints) - 1):
		string += str(lcm(ints[i], ints[i + 1]))
		string += ' '
	string += str(ints[-1])
	print(string)


def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = [A[0]]
	for i in range(N - 1):
		B.append(lcm(A[i], A[i + 1]))
	B.append(A[N - 1])
	print(' '.join(map(str, B)))


def GCD(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def GCM(a, b):
	gcd = GCD(a, b)
	return a * b // gcd
T = int(input())
for _ in range(T):
	N = int(input())
	A = [1] + list(map(int, input().split())) + [1]
	B = [0 for _ in range(N + 1)]
	for i in range(N + 1):
		B[i] = GCM(A[i], A[i + 1])
	for i in range(N + 1):
		print(str(B[i]) + ' ', end='')
	print()


from fractions import gcd

def lcm(a, b):
	return a // gcd(a, b) * b
t = int(input())

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = [None] * (n + 1)
	ans[0] = a[0]
	ans[n] = a[n - 1]
	for i in range(1, n):
		ans[i] = lcm(a[i - 1], a[i])
	print(' '.join(map(str, ans)))
for _ in range(t):
	solve()


t = int(input())

def lcm(a, b):
	h = max(a, b)
	while h % a != 0 or h % b != 0:
		h += max(a, b)
	return h
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = []
	for i in range(len(a) - 1):
		b.append(lcm(a[i], a[i + 1]))
	b.insert(0, a[0])
	b.append(a[-1])
	for u in b:
		print(u, end=' ')
	print()


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

def lcm(a, b):
	return a * b // gcd(a, b)
test = int(input())
for i in range(test):
	n = int(input())
	stri = input().split()
	A = [int(x) for x in stri]
	B = [A[-1]]
	for i in range(n - 1, 0, -1):
		B.insert(0, lcm(A[i], A[i - 1]))
	B.insert(0, A[0])
	for i in range(n + 1):
		print(B[i], end=' ')
	print()


t = int(input())

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

def lcm(a, b):
	return a * b // gcd(a, b)
while t:
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	a.append(1)
	a.insert(0, 1)
	for i in range(1, n + 2):
		print(lcm(a[i - 1], a[i]), end=' ')
	print()
	t -= 1


import fractions
T = int(input())
for T_i in range(T):
	N = int(input())
	A = [1] + [int(x) for x in input().split(' ')] + [1]
	B = []
	for A_i in range(len(A) - 1):
		(v0, v1) = (A[A_i], A[A_i + 1])
		d = fractions.gcd(v0, v1)
		B.append(str(v0 * v1 // d))
	print(' '.join(B))


from sys import stdin
from fractions import gcd
T = int(stdin.readline())

def lcm(x, y):
	return x * y // gcd(x, y)
for _ in range(T):
	N = int(stdin.readline())
	A = [int(s) for s in stdin.readline().strip().split()]
	B = [A[0]]
	for i in range(1, N):
		B.append(lcm(A[i - 1], A[i]))
	B.append(A[N - 1])
	print(' '.join((str(i) for i in B)))


def lcm(a, b):
	x = a
	y = b
	while x != y:
		if x > y:
			x = x - y
		else:
			y = y - x
	return a * b // x

def prt(A):
	for i in range(len(A) - 1):
		print(str(lcm(A[i], A[i + 1])), end=' ')
for i in range(int(input())):
	input()
	prt([1] + [int(k) for k in input().split(' ')] + [1])
	print('')


import fractions, sys

def lcm(x, y):
	return x * y // fractions.gcd(x, y)
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	A = list(map(int, sys.stdin.readline().split()))
	print(A[0], end=' ')
	for i in range(N - 1):
		print(lcm(A[i], A[i + 1]), end=' ')
	print(A[N - 1])


from fractions import *

def lcm(a, b):
	return a * b / gcd(a, b)
testCase = eval(input())
for i in range(testCase):
	n = eval(input())
	x = [int(i) for i in str(input()).split(' ')][:n]
	y = []
	y.append(x[0])
	for i in range(1, n):
		y.append(lcm(x[i - 1], x[i]))
	y.append(x[n - 1])
	for i in range(n + 1):
		print(int(y[i]), end=' ')
	print()


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

def lcm(a, b):
	return a * b / gcd(a, b)
for t in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	ans = [str(l[0])]
	for i in range(n - 1):
		ans.append(str(int(lcm(l[i], l[i + 1]))))
	ans += [str(l[-1])]
	print(' '.join(ans))


from fractions import gcd

def lcm(a, b):
	return a // gcd(a, b) * b
for _ in range(int(input())):
	input()
	B = [int(i) for i in input().split()]
	print(B[0], *[lcm(B[i], B[i + 1]) for i in range(len(B) - 1)], end=' ')
	print(B[-1])


for x in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[0], end=' ')
	j = 0
	from fractions import gcd
	while j < n - 1:
		print(int(a[j] * a[j + 1] / gcd(a[j], a[j + 1])), end=' ')
		j += 1
	print(a[n - 1])


import fractions

def lcm(a, b):
	return a * b // fractions.gcd(a, b)
for i in range(int(input())):
	input()
	a = list(map(int, input().split()))
	print(a[0], *map(lcm, a, a[1:]), end=' ')
	print(a[-1])


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

def solve(A):
	A += [1]
	p = 1
	B = []
	for a in A:
		B.append(p * a // gcd(p, a))
		p = a
	return B
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	print(' '.join((str(_) for _ in solve(A))))


def primes(n):
	if n < 3:
		return []
	if n == 3:
		return [2]
	helper = [False, False, True] + [True for _ in range(n - 3)]
	for i in range(2, n):
		for j in range(2, n // i + 1):
			if i * j < n and helper[i * j]:
				helper[i * j] = False
	nums = [i for i in range(n)]
	return [nums[i] for i in range(n) if helper[i]]
primes = primes(10 ** 4)

def factor(n):
	r = {}
	if n <= 1:
		return r
	for i in primes:
		if n % i == 0:
			r[i] = 0
			while n % i == 0:
				r[i] += 1
				n /= i
		if i == 1:
			break
	return r

def solve():
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = [A[0]]
	for i in range(1, N):
		B.append(A[i - 1])
		a = factor(A[i])
		b = factor(B[i])
		factored_b = dict(list(a.items()) + list(b.items()) + [(k, max(a[k], b[k])) for k in set(b) & set(a)])
		b = 1
		for f in factored_b:
			b *= f ** factored_b[f]
		B[i] = b
	B.append(A[-1])
	return ' '.join(map(str, B))
for case in range(int(input())):
	print(solve())


t = int(input())
for j in range(0, t):
	n = int(input())
	A = list(input())
	a = []
	x = ''
	count = 0
	for i in A:
		if i != ' ':
			x = x + i
		elif i == ' ':
			a.append(int(x))
			x = ' '
	a.append(int(x))
	b = []
	b.append(a[0])
	for j in range(1, n):
		add = min(a[j - 1], a[j])
		k = add
		found = 0
		while found == 0:
			if (k % a[j - 1] == 0) & (k % a[j] == 0):
				b.append(k)
				found = 1
			else:
				k += add
	b.append(a[n - 1])
	out = ''
	for m in range(0, n + 1):
		if m > 0:
			out += ' '
		out += str(b[m])
	print(out)


tests = int(input())
sets = []
maxv = 0
for i in range(0, tests):
	vals = int(input())
	cur = str(input()).split(' ')
	curset = []
	for j in range(0, vals):
		nowv = int(cur[j])
		if nowv > maxv:
			maxv = nowv
		curset.append(nowv)
	sets.append(curset)
primes = [2]
prim = 3
while prim <= maxv:
	pri = True
	for j in primes:
		if prim % j == 0:
			pri = False
			break
	if pri:
		primes.append(prim)
	prim += 2
for i in range(0, tests):
	prev = sets[i][0]
	print(prev, end=' ')
	for j in range(1, len(sets[i])):
		curv = sets[i][j]
		temp = prev * curv
		tp = prev
		tc = curv
		for pts in primes:
			while tp % pts == 0 and tc % pts == 0:
				temp /= pts
				tp /= pts
				tc /= pts
		print(int(temp), end=' ')
		prev = curv
	print(sets[i][len(sets[i]) - 1])


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

def lcm(a, b):
	return a // gcd(a, b) * b
t = int(input())
for case_t in range(t):
	n = int(input())
	a = [int(item) for item in input().strip().split()]
	b = [a[0]]
	for i in range(1, n):
		b.append(lcm(a[i - 1], a[i]))
	b.append(a[n - 1])
	for i in b:
		print(i, end=' ')
	print()


def lowestmultiple(a, b):
	if a > b:
		large = a
	else:
		large = b
	while 1:
		if large % a == 0 and large % b == 0:
			lcm = large
			break
		large += 1
	return lcm
T = int(input())
while T:
	b = []
	n = int(input())
	a = list(map(int, input().split()))
	b.append(a[0])
	for i in range(1, n):
		b.append(lowestmultiple(a[i], a[i - 1]))
	b.append(a[n - 1])
	for j in range(n + 1):
		print(b[j], end=' ')
	print()
	T = T - 1


import math

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

def lcm(a, b):
	temp = gcd(a, b)
	return a * b // temp
iteration = int(input())
for i in range(iteration):
	non = int(input())
	li = [int(x) for x in input().split()]
	anslist = list()
	anslist.append(str(li[0]))
	for j in range(non - 1):
		anslist.append(str(lcm(li[j], li[j + 1])))
	anslist.append(str(li[-1]))
	print(' '.join(anslist))


from fractions import gcd
for case in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n + 1)
	b[0] = a[0]
	b[-1] = a[-1]
	for i in range(1, len(b) - 1):
		b[i] = a[i - 1] * a[i] // gcd(a[i - 1], a[i])
	print(' '.join(map(str, b)))


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

def lcm(a, b):
	return a * b // gcd(a, b)
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [a[0]]
	for i in range(n - 1):
		b.append(lcm(a[i], a[i + 1]))
	b.append(a[-1])
	print(*b)


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

def lcm(a, b):
	return a * b / gcd(a, b)
T = int(input())
for t in range(T):
	N = int(input())
	d = input().split()
	A = [int(a) for a in d]
	B = []
	B.append(A[0])
	for i in range(N - 1):
		if max(A[i], A[i + 1]) % min(A[i], A[i + 1]) == 0:
			B.append(max(A[i], A[i + 1]))
		else:
			B.append(lcm(A[i], A[i + 1]))
	B.append(A[N - 1])
	out = ''
	for b in B:
		out += str(int(b)) + ' '
	print(out)


def gcd(a, b):
	while a != 0 and b != 0:
		(a, b) = (min((a, b)), max((a, b)) - min((a, b)))
	return a or b

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input().strip())):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	res = [a[0]]
	for i in range(1, len(a)):
		res.append(lcm(a[i - 1], a[i]))
	res.append(a[n - 1])
	print(' '.join(map(str, res)))


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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	elementCount = int(input())
	elements = [int(x) for x in input().split(' ')]
	output = [elements[0]]
	for i in range(1, len(elements)):
		output.append(lcm(elements[i], elements[i - 1]))
	output.append(elements[-1])
	print(' '.join((str(x) for x in output)))


def main():
	ncases = int(input())
	for _ in range(ncases):
		length = int(input())
		a = [int(fld) for fld in input().split()]
		assert len(a) == length
		print(' '.join(map(str, solve(a))))

def solve(a):
	return [x * y // gcd(x, y) for (x, y) in zip([1] + a, a + [1])]

def gcd(x, y):
	(xp2, x) = factor2s(x)
	(yp2, y) = factor2s(y)
	(x, y) = (max(x, y), min(x, y))
	while y != 0:
		(_, z) = factor2s(x - y)
		(x, y) = (max(y, z), min(y, z))
	return x << min(xp2, yp2)

def factor2s(n):
	if n == 0:
		return (0, 0)
	p2 = 0
	while n & 1 == 0:
		n >>= 1
		p2 += 1
	return (p2, n)
main()


from fractions import gcd
T = int(input())
for i in range(T):
	n = int(input())
	a = [int(num) for num in input().split()]
	b = [0 for num in range(n + 1)]
	b[0] = a[0]
	for j in range(n - 1):
		b[j + 1] = int(a[j] * a[j + 1] / gcd(a[j + 1], a[j]))
	b[n] = a[n - 1]
	print(' '.join((str(num) for num in b)))


def gcd(a, b):
	while b > 0:
		t = b
		b = a % b
		a = t
	return a
numtest = int(input())
for z in range(numtest):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	b.append(a[0])
	for i in range(n - 1):
		b.append(int(a[i] * a[i + 1] / gcd(a[i], a[i + 1])))
		print(b[i], end=' ')
	b.append(a[n - 1])
	print(b[n - 1], end=' ')
	print(b[n])


from fractions import gcd
for t in range(int(input())):
	n = int(input())
	l = list((int(i) for i in input().split()))
	s = [l[0]]
	for i in range(n - 1):
		s.append(l[i + 1] * l[i] // gcd(l[i + 1], l[i]))
	s.append(l[n - 1])
	print(str(' '.join((str(i) for i in s))))


def lcm(a, b):
	if a > b:
		(a, b) = (b, a)
	(a1, b1) = (a, b)
	while b % a != 0:
		(b, a) = (a, b % a)
	return a1 * b1 // a
t = int(input())
for i in range(t):
	n = int(input())
	l = [1] + [int(i) for i in input().split()] + [1]
	temp = []
	for j in range(1, n + 2):
		temp.append(lcm(l[j], l[j - 1]))
	print(' '.join(map(str, temp)))


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	ar = [int(i) for i in input().strip().split()]
	b = ar.copy()
	b.append(ar[n - 1])
	for i in range(n):
		c = gcd(b[i], b[i + 1])
		if c != ar[i]:
			b[i + 1] = lcm(ar[i], b[i + 1])
	print(' '.join(map(str, b)))


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	out = [a[0]]
	for i in range(n - 1):
		out.append(lcm(a[i], a[i + 1]))
	out.append(a[-1])
	print(' '.join(map(str, out)))


import fractions

def lcm(a, b):
	return a * b // fractions.gcd(a, b)
for t in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = A[0:1] + [0] * (n - 1) + A[-1:n]
	for i in range(1, n):
		B[i] = lcm(A[i - 1], A[i])
	print(' '.join([str(x) for x in B]))


import fractions
for _ in range(int(input())):
	N = int(input())
	numbers = [int(i) for i in input().split()]
	print(numbers[0], end=' ')
	for i in range(N - 1):
		a = numbers[i]
		b = numbers[i + 1]
		print(int(a * b / fractions.gcd(a, b)), end=' ')
	print(numbers[-1])


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

def lcm(a, b):
	return int(abs(a * b) / gcd(a, b))
n = int(input())
for i in range(n):
	t = int(input())
	a = [1] + [int(x) for x in input().split()] + [1]
	b = [None] * (len(a) - 1)
	for j in range(1, len(a)):
		b[j - 1] = lcm(a[j - 1], a[j])
	print(' '.join([str(x) for x in b]))


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

def lcm(a, b):
	h = hcf(a, b)
	return int(a * b // h)
t = int(input())
for tests in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	ans.append(l[0])
	for i in range(1, n):
		ans.append(lcm(l[i - 1], l[i]))
	ans.append(l[-1])
	for i in ans:
		print(i, end=' ')
	print('')


from fractions import gcd
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	out = [arr[0]]
	for i in range(n - 1):
		g = gcd(arr[i], arr[i + 1])
		if g == 1:
			out.append(arr[i] * arr[i + 1])
		else:
			out.append(arr[i] * arr[i + 1] // g)
	out.append(arr[-1])
	print(' '.join((str(x) for x in out)))


def primeFactors(N):
	Factors = list()
	i = 2
	while N > 1:
		if N % i == 0:
			Factors.append(i)
			N = N // i
		else:
			i += 1
	return Factors

def commonPrimeFactors(N, M):
	N_factors = primeFactors(N)
	M_factors = primeFactors(M)
	Common_factors = 1
	while (len(N_factors) > 0) & (len(M_factors) > 0):
		n_i = N_factors[0]
		m_i = M_factors[0]
		if n_i == m_i:
			Common_factors *= n_i
			N_factors.pop(0)
			M_factors.pop(0)
		elif n_i > m_i:
			M_factors.pop(0)
		else:
			N_factors.pop(0)
	return Common_factors
T = int(input())
for i in range(0, T):
	N = int(input())
	A_split = str(input()).split(' ')
	A = [int(A_split[j]) for j in range(0, N)]
	B = [1 for j in range(0, N + 1)]
	larger = 0
	smaller = 0
	for j in range(0, N):
		B[j] *= A[j]
		if j > 0:
			B[j] //= commonPrimeFactors(A[j - 1], A[j])
		B[j + 1] *= A[j]
	ans = ''
	for j in range(0, N + 1):
		ans += str(B[j]) + ' '
	print(ans)


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)
t = int(input())
for j in range(t):
	n = int(input())
	A = input().split()
	A = list(map(int, A))
	(x, y) = (A[0], A[-1])
	B = [x]
	for i in range(n - 1):
		LCM = lcm(A[i], A[i + 1])
		B.append(LCM)
	B.append(y)
	B = list(map(str, B))
	print(' '.join(B))


def GCD(a, b):
	return GCD(b, a % b) if b else a

def LCM(a, b):
	return a * b // GCD(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	res = [lis[0]]
	for i in range(n - 1):
		res.append(LCM(lis[i], lis[i + 1]))
	res.append(lis[-1])
	print(' '.join(list(map(str, res))))


from fractions import gcd

def lcn(a, b):
	return a * b // gcd(a, b)

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = a + a[-1:]
		for i in range(1, len(a)):
			b[i] = lcn(a[i - 1], a[i])
		print(*b)
main()


from fractions import gcd
t = int(input())
while t:
	t = t - 1
	l = []
	n = int(input())
	l = list(map(int, input().split()))
	print(l[0], end=' ')
	for x in range(n - 1):
		print(l[x] * l[x + 1] // gcd(l[x], l[x + 1]), end=' ')
	print(l[n - 1])


import string
exclude = set(string.punctuation)

def gcd(a, b):
	for i in range(min(a, b), 1, -1):
		if a % i == 0 and b % i == 0:
			return i
	return 1

def lcm(a, b):
	return a * b // gcd(a, b)
num_cases = int(input())
for _ in range(num_cases):
	length = int(input())
	array = input().split()
	array = [int(array[i]) for i in range(length)]
	result = [array[0]] * (length + 1)
	for i in range(1, length):
		result[i] = lcm(array[i - 1], array[i])
	result[length] = array[length - 1]
	print(''.join((ch for ch in str(result) if ch not in exclude)))


from fractions import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [0 for _ in range(n + 1)]
	B[0] = A[0]
	B[-1] = A[-1]
	for i in range(1, n):
		B[i] = int(A[i] * A[i - 1] / gcd(A[i], B[i - 1]))
	print(' '.join([str(x) for x in B]))


import fractions

def lcm(n, m):
	gcd1 = fractions.gcd(n, m)
	if gcd1 != 0:
		return n * m // gcd1
	else:
		return 0
nTst = int(input())
for t1 in range(nTst):
	nn = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = [arr1[0]]
	for i1 in range(1, len(arr1)):
		arr2.append(lcm(arr1[i1 - 1], arr1[i1]))
	arr2.append(arr1[-1])
	[print(el, ' ', sep='', end='') for el in arr2]
	print()


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	gcds = [int(x) for x in input().split()]
	lcms = [gcds[0]] + [lcm(gcds[i], gcds[i + 1]) for i in range(n - 1)] + [gcds[-1]]
	print(*lcms)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for test in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	print(l[0], end=' ')
	for i in range(n - 1):
		print(l[i] * l[i + 1] // gcd(l[i], l[i + 1]), end=' ')
	print(l[n - 1])


from fractions import gcd

def lcm(x, y):
	return x * y // gcd(x, y)
T = int(input())
for i in range(T):
	N = int(input())
	A = input().split()
	print(A[0], end=' ')
	for k in range(N - 1):
		print(lcm(int(A[k]), int(A[k + 1])), end=' ')
	print(A[N - 1])


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

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
while t > 0:
	b = []
	l = int(input())
	a = [int(x) for x in input().split()]
	b.append(a[0])
	for i in range(l - 1):
		b.append(lcm(a[i], a[i + 1]))
	b.append(a[-1])
	for ele in b:
		print(ele, end=' ')
	print()
	t -= 1


import sys

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a
t = int(input())
for _ in range(t):
	_ = int(input())
	aa = list(map(int, input().split()))
	aa.append(aa[-1])
	v = aa[0]
	print(v, end=' ')
	for (a, b) in zip(aa, aa[1:]):
		g = gcd(a, b)
		c = a * b // g
		g = gcd(v, c)
		w = c
		print('a=%d b=%d c=%d v=%d g=%d w=%d' % (a, b, c, v, g, w), file=sys.stderr)
		print(w, end=' ')
		v = w
	print()


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[0], end=' ')
	for i in range(1, n):
		print(lcm(a[i - 1], a[i]), end=' ')
	print(a[n - 1])


from fractions import gcd

def lcm(x, y):
	return x * y // gcd(x, y)
for _ in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().strip().split()]
	print(A[0], end=' ')
	for i in range(len(A) - 1):
		print(lcm(A[i], A[i + 1]), end=' ')
	print(A[-1])


from fractions import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[0], end=' ')
	for i in range(n - 1):
		print(a[i] * a[i + 1] // gcd(a[i], a[i + 1]), end=' ')
	print(a[-1])


gcd = lambda x, y: gcd(y % x, x) if x else y
print(*(' '.join(map(str, (lambda n, x: [x[0]] + [x[i] * x[i + 1] // gcd(x[i], x[i + 1]) for i in range(n - 1)] + [x[-1]])(int(input()), list(map(int, input().split()))))) for _ in range(int(input()))), sep='\n')


def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	print(arr[0], end=' ')
	for i in range(n - 1):
		print(arr[i] * arr[i + 1] // gcd(arr[i], arr[i + 1]), end=' ')
	print(arr[n - 1], end='\n')


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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	input()
	a = [1] + list(map(int, input().split())) + [1]
	b = [lcm(a[i], a[i + 1]) for i in range(len(a) - 1)]
	print(' '.join(map(str, b)))


from fractions import gcd
for i in range(int(input())):
	input()
	lst = [int(i) for i in input().split()]
	print(' '.join((str(i) for i in [lst[0]] + [lst[i] * lst[i + 1] // gcd(lst[i], lst[i + 1]) for i in range(len(lst) - 1)] + [lst[-1]])))


from fractions import gcd
ans = []
for i in range(int(input())):
	n = int(input())
	g = list(map(int, input().split()))
	num = []
	num.append(g[0])
	for i in range(1, n):
		num.append(g[i] * g[i - 1] // gcd(g[i], g[i - 1]))
	num.append(g[n - 1])
	ans.append(num)
for i in ans:
	for j in i:
		print(j, end=' ')
	print()


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for i in range(int(input())):
	(_, A) = (input(), [1] + list(map(int, input().split())) + [1])
	print(' '.join(map(str, map(lcm, A, A[1:]))))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		ans = [0] * (n + 1)
		ans[0] = a[0]
		ans[-1] = a[-1]
		for i in range(1, n):
			ans[i] = lcm(a[i - 1], a[i])
		for x in ans:
			print(x, end=' ')
		print()

def lcm(a, b):
	p = a * b
	if a < b:
		(a, b) = (b, a)
	while b > 0:
		(a, b) = (b, a % b)
	return int(p / a)

def lcm3(a, b, c):
	return lcm(lcm(a, b), c)
main()


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
T = int(input())
for i in range(T):
	N = int(input())
	A = [int(j) for j in input().split()]
	B = [0] + [lcm(A[i], A[i + 1]) for i in range(0, N - 1)] + [0]
	B[0] = A[0]
	B[N] = A[N - 1]
	for i in B:
		print(i, end=' ')
	print()


import fractions

def lcm(x, y):
	return x * y // fractions.gcd(x, y)
t = int(input())
for i in range(t):
	n = int(input())
	a = [0]
	a1 = [int(x) for x in input().split()]
	a = a + a1
	print(a[1], end=' ')
	for i in range(1, n):
		print(lcm(a[i], a[i + 1]), end=' ')
	print(a[n])


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	arr = [int(a) for a in input().split()]
	arr.insert(0, 1)
	arr.append(1)
	print(*[lcm(i, j) for (i, j) in zip(arr, arr[1:])])


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*map(lcm, [a[0]] + a, a + [a[-1]]))


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

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	t = int(input())
	while t != 0:
		t -= 1
		n = int(input())
		a = [int(x) for x in (input() + ' 1').split()]
		print(a[0], end=' ')
		for i in range(0, len(a) - 1):
			print(lcm(a[i], a[i + 1]), end='')
			print(' ', end='')
		print()
main()


def gcd(x, y):
	(x, y) = (max(x, y), min(x, y))
	if x == y:
		return x
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for _ in range(t):
	_ = input()
	A = [int(i) for i in input().split()]
	B = []
	B.append(A[0])
	for i in range(1, len(A)):
		b = B[i - 1]
		if b <= A[i]:
			while b % A[i] != 0:
				b += A[i - 1]
		else:
			b = A[i]
			while b % A[i - 1] != 0:
				b += A[i]
		B.append(b)
	B.append(A[-1])
	print(' '.join([str(b) for b in B]))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
tt = int(input())
for _ in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	t = [a[0]]
	for i in range(1, n):
		t.append(a[i - 1] * a[i] // gcd(a[i], a[i - 1]))
	t.append(a[-1])
	for i in t:
		print(i, end=' ')
	print()


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(xs):
	ys = [xs[0]]
	for (a, b) in zip(xs, xs[1:] + [xs[-1]]):
		ys.append(lcm(a, b))
	return ys
for _ in range(int(input())):
	n = int(input())
	xs = list(map(int, input().split()))
	print(' '.join(map(str, solve(xs))))


gcd_cache = {}

def gcd(a, b):
	if (a, b) not in gcd_cache:
		if b < 1:
			r = a
		elif a < b:
			r = gcd(b, a)
		else:
			r = gcd(b, a % b)
		gcd_cache[a, b] = r
	return gcd_cache[a, b]

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input().strip())):
	n = int(input().strip())
	alist = [int(c) for c in input().strip().split(' ')]
	p = alist.pop(0)
	rlist = [p]
	while alist:
		a = alist.pop(0)
		rlist.append(lcm(p, a))
		p = a
	rlist.append(p)
	print(' '.join((str(i) for i in rlist)))


for t0 in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	b.append(a[0])
	for i in range(len(a) - 1):
		x = 1
		while True:
			if x % a[i] == 0 and x % a[i + 1] == 0:
				b.append(x)
				break
			x = x + 1
	b.append(a[-1])
	print(*b)


t = int(input())

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

def lcm(a, b):
	return a * b // gcd(a, b)
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [1] * (len(A) + 1)
	for i in range(len(B)):
		if i == 0:
			B[i] = A[i]
		elif i == len(B) - 1:
			B[i] = A[len(A) - 1]
		else:
			B[i] = lcm(A[i], A[i - 1])
	print(' '.join([str(x) for x in B]))


from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	B.append(A[0])
	for i in range(n - 1):
		B.append(lcm(A[i], A[i + 1]))
	B.append(A[-1])
	print(' '.join(map(str, B)))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


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

def lcm(a, b):
	return a * b // gcd(a, b)
T = int(input())
for _ in range(T):
	input()
	A = list(map(int, input().split()))
	B = [A[0]]
	for (a, b) in zip(A[:-1], A[1:]):
		B.append(lcm(a, b))
	B.append(A[-1])
	print(' '.join(map(str, B)))


from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[0], end=' ')
	for i in range(n - 1):
		print(lcm(a[i], a[i + 1]), end=' ')
	print(a[n - 1])


from fractions import gcd
for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	print(l[0], end=' ')
	for i in range(n - 1):
		print(l[i] * l[i + 1] // gcd(l[i], l[i + 1]), end=' ')
	print(l[-1])


def nod(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[0], end=' ')
	for j in range(n - 1):
		print(a[j] * a[j + 1] // nod(a[j], a[j + 1]), end=' ')
	print(a[n - 1])


from fractions import gcd

def lcm(x, y):
	return x * y // gcd(x, y)
for _ in range(int(input())):
	n = int(input())
	xs = list(map(int, input().split()))
	ys = [0 for i in range(n + 1)]
	ys[-1] = xs[-1]
	for i in range(n):
		if i == 0:
			ys[i] = xs[i]
		else:
			ys[i] = lcm(xs[i - 1], xs[i])
	print(*ys)


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

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ar = [int(x) for x in input().split()]
	print(ar[0], end=' ')
	for i in range(1, n):
		print(lcm(ar[i - 1], ar[i]), end=' ')
	print(ar[-1])


t = int(input())

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
while t:
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(arr[0], end=' ')
	for k in range(n - 1):
		print(arr[k] * arr[k + 1] // gcd(arr[k], arr[k + 1]), end=' ')
	print(arr[n - 1])
	t -= 1


import math
T = int(input())
for t in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [0] * (N + 1)
	B[0] = A[0]
	B[N] = A[N - 1]
	for i in range(1, N):
		B[i] = A[i - 1] * A[i] // math.gcd(A[i - 1], A[i])
	print(*B)


import math
from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
noOfTests = int(input())
for _ in range(noOfTests):
	noOfItems = int(input())
	inputList = input().split(' ')
	inputList = [int(i) for i in inputList] + [1]
	outputList = []
	outputList.append(inputList[0])
	for i in range(1, noOfItems + 1):
		outputList.append(lcm(inputList[i], inputList[i - 1]))
	for i in outputList:
		print(i, end=' ')
	print()


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

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(arr):
	new_arr = [1] + arr + [1]
	res = []
	for (a, b) in zip(new_arr, new_arr[1:]):
		res.append(lcm(a, b))
	return res

def main():
	t = int(input())
	for _ in range(t):
		n = input()
		arr = list(map(int, input().split()))
		print(*solve(arr))
main()


from math import gcd

def lcm(x, y):
	return x // gcd(x, y) * y
for _ in range(int(input())):
	n = int(input())
	l = [1] + list(map(int, input().split())) + [1]
	ans = []
	for i in range(1, len(l)):
		ans.append(lcm(l[i], l[i - 1]))
	print(' '.join(map(str, ans)))


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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	(a, ret) = ([1] + list(map(int, input().split())) + [1], '')
	for i in range(1, n + 2):
		ret += str(lcm(a[i], a[i - 1])) + ' '
	print(ret)


from fractions import gcd
lcm = lambda a, b: a * b // gcd(a, b)
T = int(input())
for t in range(T):
	N = int(input())
	A = [1] + list(map(int, input().split())) + [1]
	print(*(lcm(A[i], A[i + 1]) for i in range(N + 1)))


from fractions import gcd

def lcm(a, b):
	return a // gcd(a, b) * b
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = [A[-1]]
	for i in range(n - 2, -1, -1):
		B.append(lcm(A[i + 1], A[i]))
	B.append(A[0])
	B.reverse()
	print(' '.join(map(str, B)))


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	ns = [int(x) for x in input().split()]
	ans = [ns[0]]
	print(' '.join(map(str, [ns[0]] + [lcm(a, b) for (a, b) in zip(ns, ns[1:])] + [ns[-1]])))


t = int(input())
import math
lcm = lambda a, b: a * b // math.gcd(a, b)

def f(a):
	c = [a[0]]
	for i in range(len(a) - 1):
		c.append(lcm(a[i], a[i + 1]))
	c.append(a[-1])
	return c
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = f(a)
	r = [str(e) for e in b]
	print(' '.join(r))


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

def lcm(a, b):
	return a * b // gcd(a, b)
T = int(input().strip())
for t in range(T):
	N = int(input().strip())
	A = [int(x) for x in input().strip().split()]
	B = [A[0]]
	for i in range(N - 1):
		B.append(lcm(A[i], A[i + 1]))
	B.append(A[-1])
	print(*B)


import math
num_q = int(input())
for _ in range(num_q):
	n = int(input())
	a = [1] + [int(x) for x in input().split()] + [1]
	for i in range(n + 1):
		g = math.gcd(a[i], a[i + 1])
		print(a[i] * a[i + 1] // g, end=' ')
	print()


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	print(a[0], end=' ')
	for j in range(1, n):
		print(int(a[j] * a[j - 1] / gcd(a[j], a[j - 1])), end=' ')
	print(a[n - 1], end=' ')
	print()


def bitize(x):
	L = []
	while x > 0:
		L.append(x % 2)
		x //= 2
	if not L:
		L = [0]
	return L

def pow_mod(a, b, m):
	b_bits = bitize(b)
	a_powers = [0 for x in b_bits]
	a_powers[0] = a % m
	if b_bits[0]:
		total = a % m
	else:
		total = 1
	for i in range(1, len(b_bits)):
		a_powers[i] = a_powers[i - 1] * a_powers[i - 1] % m
		if b_bits[i]:
			total *= a_powers[i]
			total %= m
	return total

def gcd_matrix(a, b):
	M = [[1, 0, a], [0, 1, b]]
	if a > 0 and b > 0:
		while M[0][2] != 0 and M[1][2] != 0:
			if M[0][2] > M[1][2]:
				multiple = M[0][2] // M[1][2]
				for i in range(0, 3):
					M[0][i] -= multiple * M[1][i]
			elif M[0][2] < M[1][2]:
				multiple = M[1][2] // M[0][2]
				for i in range(0, 3):
					M[1][i] -= multiple * M[0][i]
			elif M[0][2] == M[1][2]:
				return M[0][2]
		if M[0][2] == 0:
			return M[1][2]
		else:
			return M[0][2]
	elif a != 0 and b != 0:
		return gcd_matrix(abs(a), abs(b))
	else:
		return 0

def is_prime(x, L=[]):
	sqrt = int(pow(x, 0.5)) + 1
	PL = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
	if not L:
		if x < 210:
			if x in PL:
				return True
			else:
				return False
		else:
			for p in PL:
				if x % p == 0:
					return False
			for i in range(1, sqrt // 210 + 1):
				for j in [1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209]:
					if x % (210 * i + j) == 0:
						return False
		return True
	elif x != 0 and x != 1:
		j = 0
		while j < len(L) and L[j] <= sqrt:
			if x % L[j] == 0:
				return False
			j += 1
	else:
		return False
	return True

def is_miller_rabin(x, num_tests=3):
	k = x - 1
	e = 0
	while k % 2 == 0:
		e += 1
		k //= 2
	tests = [False for _ in range(0, num_tests)]
	A = [2, 3, 5]
	for j in range(3, num_tests):
		A.append(random.randint(7, x - 1))
	if x < 2047:
		num_tests = 1
	elif x < 1373653:
		num_tests = 2
	elif x < 25326001:
		num_tests = 3
	for i in range(0, num_tests):
		ak = pow_mod(A[i], k, x)
		if ak == 1:
			tests[i] = True
		else:
			for j in range(0, e):
				if ak == x - 1:
					tests[i] = True
				ak = ak * ak % x
	for i in range(0, num_tests):
		if not tests[i]:
			return False
	return True

def factor(n, PL):
	sqrt = int(pow(n, 0.5)) + 1
	factor_list = []
	if not PL:
		PL = prime_list(sqrt)
	for p in PL:
		if n % p == 0:
			elet = [p, 0]
			while not n % p:
				n //= p
				elet[1] += 1
			factor_list.append(elet)
	if n != 1:
		if is_miller_rabin(n):
			factor_list.append([n, 1])
	return factor_list

def prime_list(n):
	L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
	for k in range(1, n // 210):
		for j in [1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209]:
			if is_prime(210 * k + j, L):
				L.append(210 * k + j)
	k = n // 210
	for j in [1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209]:
		if is_prime(210 * k + j, L) and 210 * k + j <= n:
			L.append(210 * k + j)
	return L
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) for a in input().split()]
	A.append(1)
	B = [0 for x in A]
	B[0] = A[0]
	for i in range(1, len(A)):
		B[i] = A[i] * A[i - 1] // gcd_matrix(A[i], A[i - 1])
	print(' '.join([str(b) for b in B]))


import math
for _ in range(int(input())):
	n = int(input())
	r = [0] * (n + 1)
	l = list(map(int, input().split()))
	for i in range(n):
		r[i + 1] = l[i]
		r[i] = r[i] * l[i] // math.gcd(r[i], l[i])
	r[0] = l[0]
	print(*r)


def gcd(p, q):
	return p if q == 0 else gcd(q, p % q)

def lcm(p, q):
	return p * q // gcd(p, q)
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	l = len(A)
	B = [0] * (l + 1)
	B[0] = A[0]
	for i in range(1, l):
		B[i] = lcm(A[i - 1], A[i])
	B[l] = A[l - 1]
	print(*B)


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

def lcm(x):
	return x[0] * x[1] // gcd(x[0], x[1])

def calc(a):
	return list(map(lambda x: lcm(x), list(zip(a + [1], [1] + a))))
for _ in range(int(input())):
	_ = input()
	a = list(map(int, input().strip().split()))
	print(' '.join(list(map(str, calc(a)))))