You are given an array $[a_1, a_2, \dots, a_n]$ such that $1 \le a_i \le 10^9$. Let $S$ be the sum of all elements of the array $a$.

Let's call an array $b$ of $n$ integers beautiful if:

$1 \le b_i \le 10^9$ for each $i$ from $1$ to $n$;

for every pair of adjacent integers from the array $(b_i, b_{i + 1})$, either $b_i$ divides $b_{i + 1}$, or $b_{i + 1}$ divides $b_i$ (or both);

$2 \sum \limits_{i = 1}^{n} |a_i - b_i| \le S$.

Your task is to find any beautiful array. It can be shown that at least one beautiful array always exists.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case consists of two lines. The first line contains one integer $n$ ($2 \le n \le 50$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$).


-----Output-----

For each test case, print the beautiful array $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$) on a separate line. It can be shown that at least one beautiful array exists under these circumstances. If there are multiple answers, print any of them.


-----Examples-----

Input
4
5
1 2 3 4 5
2
4 6
2
1 1000000000
6
3 4 8 1 2 3
Output
3 3 3 3 3
3 6
1 1000000000
4 4 8 1 3 3


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM
Tags: Bit manipulation

Constructive algorithms

Greedy algorithms


Solutions:
def func(n, arr):
	s = sum(arr)
	odds = [1 if i & 1 else arr[i] for i in range(n)]
	if sum(map(lambda i: abs(odds[i] - arr[i]), range(n))) << 1 <= s:
		return odds
	return [1 if i & 1 == 0 else arr[i] for i in range(n)]
for _ in range(int(input())):
	print(*func(int(input()), list(map(int, input().split()))))


T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	a = list(map(int, input('').split()))
	Sum = sum(a)
	tot = 0
	i = 0
	while i < n:
		tot += 2 * (a[i] - 1)
		i += 2
	if tot <= Sum:
		i = 0
		ans = []
		while i < n:
			if i % 2 == 1:
				ans.append(a[i])
			else:
				ans.append(1)
			i += 1
		print(*ans)
	else:
		i = 0
		ans = []
		while i < n:
			if i % 2 == 0:
				ans.append(a[i])
			else:
				ans.append(1)
			i += 1
		print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ary = [int(i) for i in input().split()]
	for num in ary:
		a = 1
		while a * 2 <= num:
			a *= 2
		print(a, end=' ')
	print('')


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')
di8 = ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
di4 = ((1, 0), (0, 1), (-1, 0), (0, -1))

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	prime[0] = prime[1] = False
	return (a, prime)

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n, r):
	return M.factorial(n) // M.factorial(n - r)

def IF(c, t, f):
	return t if c else f

def YES(c):
	print(IF(c, 'YES', 'NO'))

def Yes(c):
	print(IF(c, 'Yes', 'No'))

def yes(c):
	print(IF(c, 'yes', 'no'))

def JA(a, sep=' '):
	print(sep.join(map(str, a)))

def JAA(a, s='\n', t=' '):
	return s.join((t.join(map(str, b)) for b in a))

def PS(a, s=' '):
	print(str(a), end=s)

def I():
	return int(inp())

def F():
	return float(inp())

def LI():
	return list(map(int, inp().split()))

def LF():
	return list(map(float, inp().split()))

def MATI(n):
	return [LI() for i in range(n)]

def MATS(n):
	return [list(inp()) for i in range(n)]

def IV():
	return map(int, inp().split())

def FV():
	return map(float, inp().split())

def LS():
	return list(inp())

def S():
	return inp()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 1

def solve():
	n = I()
	arr = LI()
	for i in arr:
		PS(2 ** pow2(i))
	print()

def main():
	flag = 1
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 0
	t = 1
	if TestCases:
		t = I()
	for _ in range(1, t + 1):
		solve()
	if flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	z = []
	for t in range(a):
		if t % 2 == 1:
			z.append(l[t])
		else:
			z.append(1)
	bb = []
	for i in range(a):
		if i % 2 == 0:
			bb.append(l[i])
		else:
			bb.append(1)
	if sum(z) <= sum(l) // 2:
		print(*bb)
	else:
		print(*z)


import sys
import math
CASE = 1
rla = ''
inf = 998244353535353535353

def solve():
	n = int(input())
	li = [int(i) for i in input().split()]
	sum1 = 0
	sum2 = 0
	m = 0
	for i in li:
		if m == 0:
			sum1 += abs(1 - i)
		else:
			sum2 += abs(1 - i)
		m ^= 1
	if sum(li) >= 2 * sum1:
		m = 0
	else:
		m = 1
	for i in li:
		print(1 if m == 0 else i, end=' ')
		m ^= 1
	print()
while True:
	rla = sys.stdin.readline()
	cases = 1
	if not rla:
		break
	if (rla == '\n') | (rla == ''):
		continue
	if CASE == 1:
		cases = int(rla)
	for cas in range(cases):
		solve()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *

def solve():
	input()
	a = list(map(int, input().split()))
	z = sum(a)
	b = []
	for i in a:
		p = 1
		while p <= i:
			p = p * 2
		b.append(p // 2 + (p == 1))
	return b

def main():
	for _ in range(int(input())):
		print(*solve())
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	cur = [0, 0]
	for i in range(n):
		cur[i % 2] += a[i] - 1
	for j in range(2):
		if 2 * cur[j] > s:
			continue
		for i in range(n):
			if i % 2 == j:
				a[i] = 1
		break
	print(*a)


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	for i in range(2):
		ans = []
		for j in range(n):
			if i == 0:
				if j % 2 == 0:
					ans.append(1)
				else:
					ans.append(arr[j])
			elif j % 2 == 0:
				ans.append(arr[j])
			else:
				ans.append(1)
		val = 0
		for j in range(n):
			val += abs(arr[j] - ans[j])
		if 2 * val <= sum(arr):
			print(*ans)
			break


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for x in a:
		mn = float('inf')
		best = 0
		for i in range(0, 30):
			if abs(2 ** i - x) < mn:
				mn = abs(2 ** i - x)
				best = 2 ** i
		ans.append(best)
	print(*ans)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		S0 = S1 = 0
		for (i, a) in enumerate(A):
			if i & 1:
				S1 += a
			else:
				S0 += a
		if S0 < S1:
			B = []
			for (i, a) in enumerate(A):
				if i & 1:
					B.append(a)
				else:
					B.append(1)
		else:
			B = []
			for (i, a) in enumerate(A):
				if i & 1:
					B.append(1)
				else:
					B.append(a)
		print(*B)
main()


def gen_beautiful_arr(arr, parity):
	res = []
	for c in range(len(arr)):
		if c % 2 == parity:
			res.append(arr[c])
		else:
			res.append('1')
	return res

def main():
	T = int(input())
	for c in range(T):
		n = int(input())
		arr = input().rstrip().split(' ')
		s_even = s_odd = 0
		for c in range(n):
			if c % 2 == 0:
				s_odd += int(arr[c]) - 1
			else:
				s_even += int(arr[c]) - 1
		print(' '.join(gen_beautiful_arr(arr, 1 if s_odd < s_even else 0)))
main()


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
f = []

def factMod(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fact(n):
	global f
	f = [1 for i in range(n)]
	for i in range(1, n):
		f[i] = f[i - 1] * i

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncrMod(n, r, m):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def ncr(n, r):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] / (f[r] * f[n - r])

def nc2(n):
	return n * (n - 1) / 2

def main():
	B()

def A():
	t = pi()
	while t:
		t -= 1
		a = ti()
		s = a[0] + a[1] + a[2]
		x = math.floor(s / 9)
		if s < 7 or a[0] < x or a[1] < x or (a[2] < x):
			print('NO')
			continue
		if s % 9 == 0:
			print('YES')
		else:
			print('NO')

def B():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = ti()
		b = [0 for i in range(n)]
		s = s1 = s2 = 0
		for i in range(n):
			s += a[i]
			if i % 2 == 0:
				s1 += a[i]
			else:
				s2 += a[i]
		if s1 > s / 2:
			for i in range(n):
				if i % 2 != 0:
					b[i] = 1
				else:
					b[i] = a[i]
		else:
			for i in range(n):
				if i % 2 != 0:
					b[i] = a[i]
				else:
					b[i] = 1
		print(*b, sep=' ')
main()


import math
from random import random

def read(t=int):
	lis = input().strip().split()
	return list(map(t, lis))
t = read()[0]

def check(lis, a, s):
	cnt = 0
	for (x, y) in zip(lis, a):
		cnt += abs(x - y)
	return 2 * cnt <= s
for i in range(t):
	n = read()[0]
	a = read()
	s = sum(a)
	mm = max(a)
	res = [max(1, 2 ** int(math.log(j, 2))) for j in a]
	print(*res)


t = int(input())
for q in range(t):
	n = int(input())
	mass = [int(x) for x in input().split()]
	answer = 0
	for i in range(n - 1):
		if mass[i] % mass[i + 1] != 0 and mass[i + 1] % mass[i] != 0:
			mass[i + 1] = max(1, mass[i + 1] - mass[i + 1] % mass[i])
	print(*mass)


import sys
from math import log2
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0] * n
	for i in range(n):
		x = int(log2(arr[i]))
		ans[i] = 2 ** x
	print(*ans)


from math import log2
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in l:
		z = int(log2(i))
		print(2 ** z, end=' ')
	print()


import sys
input = sys.stdin.readline
print = sys.stdout.write

def ii():
	return int(input())

def mii():
	return map(int, input().rstrip().split())

def lmii():
	return list(map(int, input().rstrip().split()))
t = ii()
for _ in range(t):
	n = ii()
	A = lmii()
	for i in range(n):
		tmp = 1
		while tmp <= A[i]:
			tmp *= 2
		print(str(tmp // 2) + ' ')
	print('\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = [0, 0]
	for i in range(n):
		res[i % 2] += a[i] - 1
	for i in range(2):
		if 2 * res[i] <= sum(a):
			for j in range(n):
				if j % 2 == i:
					a[j] = 1
			break
	print(*a)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		if i % 2:
			b.append(a[i])
		else:
			b.append(1)
	if sum([abs(a[i] - b[i]) for i in range(n)]) * 2 <= sum(a):
		print(' '.join([str(i) for i in b]))
	else:
		b = []
		for i in range(n):
			if not i % 2:
				b.append(a[i])
			else:
				b.append(1)
		print(' '.join([str(i) for i in b]))


import math
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(n):
		b[i] = 2 ** int(math.log(a[i], 2))
	print(*b, sep=' ')


from collections import Counter
import math
import sys
import heapq
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	a = LIST()
	s = 0
	s1 = 0
	s = sum(a)
	b = [0 for i in range(n)]
	for i in range(n):
		if i % 2 == 0:
			b[i] = a[i]
		else:
			b[i] = 1
		s1 += abs(a[i] - b[i])
	ans = []
	if s >= 2 * s1:
		print(*b)
	else:
		for i in range(n):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(a[i])
		print(*ans)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			even.append(1)
			odd.append(a[i])
		else:
			odd.append(1)
			even.append(a[i])
	o = 0
	e = 0
	for i in range(n):
		o += abs(a[i] - odd[i])
		e += abs(a[i] - even[i])
	s = sum(a)
	if o <= s / 2:
		print(*odd)
	else:
		print(*even)


t = int(input())
for _ in range(t):
	n = input()
	A = list(map(int, input().split()))
	B = []
	for a in A:
		if a == 1:
			B.append(1)
		else:
			div = B[-1] if len(B) > 0 else 2
			q = a // div
			if q != 0:
				B.append(q * div)
			else:
				B.append(1)
	print(' '.join(list(map(str, B))))


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	s = sum(a)
	odd = [a[i] if i % 2 == 1 else 1 for i in range(n)]
	if sum((abs(odd[i] - a[i]) for i in range(n))) * 2 <= s:
		print(' '.join(map(str, odd)))
		continue
	even = [a[i] if i % 2 == 0 else 1 for i in range(n)]
	print(' '.join(map(str, even)))


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 1
	for i in range(len(a)):
		if i % 2 == 0:
			cnt0 += a[i]
		else:
			cnt1 += a[i]
	if cnt0 < cnt1:
		for i in range(len(a)):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(a[i], end=' ')
		print()
	else:
		for i in range(len(a)):
			if i % 2 == 1:
				print(1, end=' ')
			else:
				print(a[i], end=' ')
		print()


test = int(input())
for sdfas in range(test):
	n = int(input())
	l = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2:
			odd += l[i]
		else:
			even += l[i]
	if odd >= even:
		for i in range(n):
			if i % 2:
				print(l[i], end=' ')
			else:
				print(1, end=' ')
	else:
		for i in range(n):
			if i % 2:
				print(1, end=' ')
			else:
				print(l[i], end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	if_a_good = True
	for j in range(n - 1):
		if a[j] % a[j + 1] != 0 and a[j + 1] % a[j] != 0:
			if_a_good = False
			break
	if if_a_good == True:
		print(' '.join([str(j) for j in a]))
	else:
		b1 = a.copy()
		b2 = a.copy()
		diff1 = 0
		diff2 = 0
		for j in range(n):
			if j % 2 == 1:
				b1[j] = 1
				diff1 += abs(a[j] - b1[j])
			else:
				b2[j] = 1
				diff2 += abs(a[j] - b2[j])
		if diff1 <= sum(a) // 2:
			print(' '.join([str(j) for j in b1]))
		else:
			print(' '.join([str(j) for j in b2]))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans1 = a[:]
	ans2 = a[:]
	dif1 = 0
	dif2 = 0
	for i in range(n):
		if i % 2:
			ans1[i] = 1
			dif1 += a[i] - 1
		else:
			ans2[i] = 1
			dif2 += a[i] - 1
	if 2 * dif1 < sum(a):
		print(*ans1)
	else:
		print(*ans2)


innum = lambda : int(input())
inmul = lambda : map(int, input().split())
instr = lambda : str(input())
inarr = lambda : list(map(int, input().split()))

def solve():
	n = innum()
	a = inarr()
	s = sum(a)
	seq1 = [a[i] if i % 2 == 0 else 1 for i in range(n)]
	seq2 = [1 if i % 2 == 0 else a[i] for i in range(n)]
	s1 = sum([abs(a[i] - seq1[i]) for i in range(n)])
	s2 = sum([abs(a[i] - seq2[i]) for i in range(n)])
	if 2 * s1 <= s:
		print(*seq1)
	else:
		print(*seq2)

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


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = ['NO'] * t
	for ti in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		ans_a[ti] = ' '.join(map(str, [1 << len(bin(x)) - 3 for x in a]))
	output(*ans_a)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	array = [int(x) for x in input().split()]
	s = sum(array)
	cur = [0, 0]
	for i in range(n):
		cur[i % 2] += array[i] - 1
	for j in range(2):
		if 2 * cur[j] > s:
			continue
		for i in range(n):
			if i % 2 == j:
				array[i] = 1
		break
	for i in range(n):
		print(array[i], end=' ')
	print()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(s1, s2) = (0, 0)
	for i in range(n):
		if i % 2:
			s1 += a[i]
		else:
			s2 += a[i]
	if s1 > s2:
		for i in range(n):
			if i % 2:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
	else:
		for i in range(n):
			if i % 2 == 0:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
	print()


from sys import stdin
q = int(input())
for j in range(q):
	n = int(input())
	c = list(map(int, input().split()))
	s = [0, 0]
	for i in range(n):
		s[i % 2] += c[i]
	if s[0] > s[1]:
		for i in range(n):
			if i % 2:
				c[i] = 1
	else:
		for i in range(n):
			if i % 2 == 0:
				c[i] = 1
	print(*c)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	o = 0
	e = 0
	for i in range(n):
		if i % 2 == 0:
			e += arr[i]
		else:
			o += arr[i]
	if o > e:
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(arr[i], end=' ')
	else:
		for i in range(n):
			if i % 2 == 1:
				print(1, end=' ')
			else:
				print(arr[i], end=' ')
	print('')


from math import log2
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = []
	for i in a:
		x = int(log2(i))
		k.append(pow(2, x))
	print(*k)


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			even += a[i]
		else:
			odd += a[i]
	b = [0] * n
	if even > odd:
		i = 0
	else:
		i = 1
	for j in range(i, n, 2):
		b[j] = a[j]
	for i in range(n):
		if b[i] == 0:
			b[i] = 1
	print(*b)


for _ in range(int(input())):
	n = int(input())
	a = [x for x in map(int, input().split())]
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0:
			odd += abs(a[i] - 1)
		else:
			even += abs(a[i] - 1)
	if odd > even:
		for i in range(n):
			if i % 2 == 1:
				print(1, end=' ')
			else:
				print(a[i], end=' ')
	else:
		for i in range(n):
			if i % 2 == 1:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
	print()


tests = int(input())
for t in range(tests):
	n = int(input())
	ls = list(map(int, input().split()))
	ls_others = [2 ** i for i in range(0, 30)]
	ans = []
	for item in ls:
		for sel_idx in range(len(ls_others)):
			if sel_idx < len(ls_others) - 1:
				if abs(item - ls_others[sel_idx]) <= abs(item - ls_others[sel_idx + 1]):
					ans.append(ls_others[sel_idx])
					break
			else:
				ans.append(ls_others[sel_idx])
	print(' '.join([str(item) for item in ans]))


def arraycreator(lst):
	s = sum(lst)
	ind = lst.index(max(lst))
	blanck1 = [1] * len(lst)
	blanck2 = [1] * len(lst)
	for i in range(1, len(lst), 2):
		blanck1[i] = lst[i]
	for i in range(0, len(lst), 2):
		blanck2[i] = lst[i]
	lst3 = list(map(lambda x, y: abs(x - y), lst, blanck1))
	if 2 * sum(lst3) <= s:
		print(*blanck1)
		return ''
	lst4 = list(map(lambda x, y: abs(x - y), lst, blanck2))
	if 2 * sum(lst4) <= s:
		print(*blanck2)
		return ''
	for i in set(lst):
		lst2 = [i] * len(lst)
		lst3 = list(map(lambda x, y: abs(x - y), lst, lst2))
		if 2 * sum(lst3) <= s:
			print(*lst2)
			return ''
t = int(input())
for i in range(t):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(arraycreator(lst))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	for i in range(n):
		x = 1
		while x * 2 <= l[i]:
			x = x * 2
		ans.append(x)
	print(*ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
from copy import deepcopy
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def check():
	return 2 * sum([abs(answer[i] - arr[i]) for i in range(n)]) <= sum(arr)
for _ in range(int(data())):
	n = int(data())
	arr = l()
	answer = [1] * n
	for i in range(0, n, 2):
		answer[i] = arr[i]
	if check():
		outa(*answer)
		continue
	answer = [1] * n
	for i in range(1, n, 2):
		answer[i] = arr[i]
	outa(*answer)


from sys import stdin as si, stdout as so
from math import floor
for _ in range(int(si.readline())):
	n = int(si.readline())
	a = list(map(int, si.readline().split()))
	s1 = 0
	s2 = 0
	for i in range(0, n, 2):
		s1 += a[i]
	for i in range(1, n, 2):
		s2 += a[i]
	if s1 > s2:
		for i in range(0, n):
			if i % 2 == 0:
				so.write(str(a[i]) + ' ')
			else:
				so.write(str(1) + ' ')
	else:
		for i in range(0, n):
			if i % 2 != 0:
				so.write(str(a[i]) + ' ')
			else:
				so.write(str(1) + ' ')
	so.write('\n')


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		k = []
		for i in a:
			x = int(math.log2(i))
			k.append(pow(2, x))
		print(*k)
main()


from collections import defaultdict, deque
import sys
import bisect
input = sys.stdin.readline
mod = 1000000007

def calc(num):
	ret = 0
	for i in range(n):
		ret += abs(a[i] - num[i])
	return ret
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(ans, ans1) = ([], [])
	for i in range(n):
		if i & 1:
			ans.append(1)
			ans1.append(a[i])
		else:
			ans.append(a[i])
			ans1.append(1)
	(one, two) = (calc(ans), calc(ans1))
	if sum(a) - 2 * one >= 0:
		print(*ans)
	else:
		print(*ans1)


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = []
	for i in l:
		x = int(math.log(i, 2))
		k.append(2 ** x)
	print(*k)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(len(arr)):
		x = bin(arr[i])[2:]
		if len(x) > 1:
			x = '1' + '0' * (len(x) - 1)
		arr[i] = int(x, 2)
	print(*arr)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	s1 = 0
	s2 = 0
	for i in range(n):
		if i % 2 == 0:
			s1 += l[i]
		else:
			s2 += l[i]
	if 2 * s2 <= s:
		for i in range(n):
			if i % 2 == 0:
				print(l[i], end=' ')
			else:
				print(1, end=' ')
	else:
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(l[i], end=' ')
	print()


import math
for _ in range(int(input())):
	n = int(input())
	array = [int(i) for i in input().split()]
	ans = [0 * n]
	for i in range(n):
		temp = int(math.log(array[i], 2))
		if abs(array[i] - 2 ** temp) < abs(array[i] - 2 ** (temp + 1)):
			array[i] = 2 ** temp
		elif 2 ** (temp + 1) > 10 ** 9:
			array[i] = 2 ** temp
		else:
			array[i] = 2 ** (temp + 1)
	print(*array)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in a:
		print(1 << len(bin(i)[2:]) - 1, end=' ')
	print()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	sumodd = 0
	sumev = 0
	for i in range(n):
		if i % 2 == 0:
			sumev += l[i]
		else:
			sumodd += l[i]
	if sumodd >= sumev:
		for i in range(n):
			if i % 2 == 0:
				l[i] = 1
	else:
		for i in range(n):
			if i % 2 > 0:
				l[i] = 1
	for i in range(n):
		print(l[i], end=' ')
	print()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	sum_a = 0
	for i in a:
		sum_a += i
	first_arr = [0] * n
	second_arr = [0] * n
	for i in range(n):
		if i % 2 == 0:
			first_arr[i] = a[i]
			second_arr[i] = 1
		else:
			first_arr[i] = 1
			second_arr[i] = a[i]
	(dif1, dif2) = (0, 0)
	for i in range(n):
		dif1 += abs(a[i] - first_arr[i])
		dif2 += abs(a[i] - second_arr[i])
	if 2 * dif1 <= sum_a:
		print(*first_arr, sep=' ')
	else:
		print(*second_arr, sep=' ')
t = int(input())
for q in range(t):
	solve()


import math as mt
for _ in range(int(input())):
	_ = int(input())
	t = list(map(int, input().split(' ')))
	for i in t:
		print(2 ** int(mt.log(i, 2)), end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd_sum = 0
	for i in range(1, n, +2):
		odd_sum += a[i]
	even_sum = 0
	for i in range(0, n, +2):
		even_sum += a[i]
	final_arr = []
	if odd_sum <= even_sum:
		for i in range(0, n):
			if i % 2 == 0:
				final_arr.append(a[i])
			else:
				final_arr.append(1)
	else:
		for i in range(0, n):
			if i % 2 == 0:
				final_arr.append(1)
			else:
				final_arr.append(a[i])
	print(*final_arr)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = []
	for i in range(n):
		num1 = 0
		while 2 ** num1 <= ar[i]:
			num1 += 1
		if 2 ** num1 - ar[i] > ar[i] - 2 ** (num1 - 1) or 2 ** num1 > 10 ** 9:
			ans.append(2 ** (num1 - 1))
		else:
			ans.append(2 ** num1)
	print(*ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def bam(x):
	b = x.bit_length()
	a = 1 << b - 1
	c = 2 * a
	if x - a <= c - x:
		return a
	else:
		if c > 10 ** 9:
			return a
		return c

def solve(n, ass):
	return [bam(x) for x in ass]
for _ in range(inp()):
	n = inp()
	ass = inlt()
	print(*solve(n, ass))


test = int(input())
for t in range(0, test):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	s0 = 0
	s1 = 0
	for i in range(0, len(a)):
		if i % 2:
			s1 += a[i]
		else:
			s0 += a[i]
	if s0 > s1:
		for i in range(0, len(a)):
			if i % 2:
				print(1, end=' ')
			else:
				print(a[i], end=' ')
	else:
		for i in range(0, len(a)):
			if i % 2:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	sodd = 0
	seven = 0
	for i in range(n):
		if i % 2 == 0:
			seven += l[i] - 1
		else:
			sodd += l[i] - 1
	if 2 * seven <= s:
		for i in range(n):
			if i % 2 == 0:
				l[i] = 1
	else:
		for i in range(n):
			if i % 2 != 0:
				l[i] = 1
	print(*l)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	count = 0
	count2 = 0
	for i in range(n):
		if i % 2 == 0:
			l1.append(1)
			count += abs(l[i] - 1)
		else:
			l1.append(l[i])
	l2 = []
	for i in range(n):
		if i % 2 == 0:
			l2.append(l[i])
		else:
			l2.append(1)
			count2 += abs(l[i] - 1)
	s = sum(l)
	if count <= s // 2:
		print(*l1)
	else:
		print(*l2)


import math
t = int(input())
for o in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	b = []
	for i in l:
		x = int(math.log2(i))
		b.append(2 ** x)
	print(*b)


from functools import lru_cache
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	sums = [0, 0]
	for i in range(n):
		sums[i % 2] += arr[i] - 1
	for j in range(2):
		if 2 * sums[j] > s:
			continue
		for i in range(n):
			if i % 2 == j:
				arr[i] = 1
		break
	print(*arr)


for iii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arra = []
	for i in range(n):
		if i % 2 == 0:
			arra.append(1)
		else:
			arra.append(arr[i])
	arrb = []
	for ii in range(n):
		if ii % 2:
			arrb.append(1)
		else:
			arrb.append(arr[ii])
	sum1 = 0
	for j in range(n):
		sum1 += abs(arr[j] - arra[j])
	if 2 * sum1 <= sum(arr):
		print(*arra)
	else:
		print(*arrb)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
import functools
from operator import ixor
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	q = int(input())
	a = list(map(int, input().split()))
	b = [0] * q
	w = 0
	e = 0
	for i in range(q):
		if i % 2 == 0:
			w += a[i]
		else:
			e += a[i]
	if w > e:
		for i in range(q):
			if i % 2 == 0:
				b[i] = a[i]
			else:
				b[i] = 1
	else:
		for i in range(q):
			if i % 2 != 0:
				b[i] = a[i]
			else:
				b[i] = 1
	print(*b)


from collections import defaultdict, Counter
import sys
import bisect

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	sm = sum(a[::2])
	b = [1] * n
	if sm > sum(a) // 2:
		for i in range(0, n, 2):
			b[i] = a[i]
	else:
		for i in range(1, n, 2):
			b[i] = a[i]
	print(*b)


for _ in range(int(input())):
	n = int(input())
	A = [int(a) for a in input().split()]
	odd = []
	even = []
	s_odd = 0
	s_even = 0
	for i in range(n):
		if i % 2 == 0:
			odd.append(A[i])
			s_odd += A[i]
			even.append(1)
			s_even += 1
		else:
			even.append(A[i])
			s_even += A[i]
			odd.append(1)
			s_odd += 1
	B = []
	if s_odd < s_even:
		B = even
	else:
		B = odd
	print(*B)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def func(n, arr):
	s = sum(arr)
	odds = [1 if i & 1 else arr[i] for i in range(n)]
	if sum(map(lambda i: abs(odds[i] - arr[i]), range(n))) << 1 <= s:
		return odds
	return [1 if i & 1 == 0 else arr[i] for i in range(n)]

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


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	c = [1 for i in range(n)]
	add = 0
	while i < n:
		add += a[i]
		i += 2
	sum = 0
	i = 1
	while i < n:
		sum += a[i]
		i += 2
	if add > sum:
		i = 0
		while i < n:
			c[i] = a[i]
			i += 2
	else:
		i = 1
		while i < n:
			c[i] = a[i]
			i += 2
	for i in range(n):
		print(c[i], end=' ')
	print()


from math import *
for i in range(int(input())):
	leng = int(input())
	a = list(map(int, input().strip().split()))
	a.append(a[-1])
	b = []
	for i in range(leng):
		try:
			short1 = pow(2, ceil(log(a[i]) / log(2)))
			short2 = pow(2, floor(log(a[i]) / log(2)))
			short = max(1, min(short1, short2))
			if short > 1000000000:
				short = pow(2, floor(log(1000000000) / log(2)))
			b.append(int(short))
		except:
			pass
	for each in b:
		print(each, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	p = [0, 0]
	for i in range(n):
		p[i % 2] += l[i] - 1
	for i in range(2):
		if 2 * p[i] > s:
			continue
		for j in range(n):
			if j % 2 == i:
				l[j] = 1
		break
	print(*l)


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, a):
	b = []
	for i in range(n):
		b.append(1 << math.floor(math.log(a[i], 2)))
	return b
t = int(input())
result = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	result.append(f(n, a))
for i in range(t):
	for j in range(len(result[i])):
		print(result[i][j], end=' ')
	print()


import sys

def main():

	def modst(a, s):
		ret = 1
		while s:
			if s % 2:
				ret = ret * a % mod
			a = a * a % mod
			s //= 2
		return ret

	def Cnk(n, k):
		return (k <= n and n >= 0) * (f[n] * modst(f[k] * f[n - k] % mod, mod - 2) % mod)
	n = int(sys.stdin.readline().strip())
	q = list(map(int, sys.stdin.readline().split()))
	fl = sum([q[i] for i in range(0, n, 2)]) > sum([q[i] for i in range(1, n, 2)])
	print(*[1 if i % 2 == fl else q[i] for i in range(n)])
for i in range(int(input())):
	main()


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	even = sum(a[::2])
	odd = sum(a[1::2])
	if even >= odd:
		i = 0
		while i < n:
			if i % 2 == 0:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
			i += 1
	else:
		i = 0
		while i < n:
			if i % 2 == 1:
				print(a[i], end=' ')
			else:
				print(1, end=' ')
			i += 1
	print('')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	(e, o) = (0, 0)
	for i in range(0, n, 2):
		e += a[i]
	for i in range(1, n, 2):
		o += a[i]
	if o >= e:
		for i in range(n):
			if i % 2 == 0:
				b[i] = 1
			else:
				b[i] = a[i]
	else:
		for i in range(n):
			if i % 2 == 0:
				b[i] = a[i]
			else:
				b[i] = 1
	print(*b)


T = int(input())
r = 1
while r <= T:
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	for ele in arr:
		s = bin(ele)
		base = 1 << len(s) - 3
		if base > 1 and ele >= base + base // 2:
			base *= 2
		if base > 10 ** 9:
			base = base // 2
		ans.append(base)
	ans = map(str, ans)
	print(' '.join(ans))
	r += 1


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

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

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def solve():
	n = N()
	ar = lis()
	s = sum(ar)
	od = 0
	ev = 0
	ans = []
	for i in range(n):
		if i % 2 == 1:
			od += ar[i]
		else:
			ev += ar[i]
	if ev >= od:
		for i in range(n):
			if i % 2 == 0:
				ans.append(ar[i])
			else:
				ans.append(1)
		print(*ans)
	else:
		for i in range(n):
			if i % 2 == 1:
				ans.append(ar[i])
			else:
				ans.append(1)
		print(*ans)
testcase(int(inp()))


import sys
from math import log2

def read(func=int):
	return func(sys.stdin.readline().strip())

def readList(func=int):
	return list(map(func, sys.stdin.readline().strip().split()))
t = read()
for _ in range(t):
	n = read()
	A = readList()
	B = []
	for i in range(n):
		num = int(log2(A[i]))
		B.append(2 ** num)
	print(*B)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	s = sum(A)
	cur = [0, 0]
	for i in range(n):
		cur[i % 2] += A[i] - 1
	for j in range(2):
		if 2 * cur[j] > s:
			continue
		for i in range(n):
			if i % 2 == j:
				A[i] = 1
		break
	for i in A:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	b = [0] * n
	for i in range(n):
		b[i] = arr[i] if i % 2 == 0 else 1
	su = 0
	for i in range(n):
		su += abs(arr[i] - b[i])
	if 2 * su > s:
		for i in range(n):
			b[i] = arr[i] if i % 2 == 1 else 1
	print(*b)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = []
	for i in range(n):
		if i % 2 == 0:
			flag.append(1)
		else:
			flag.append(a[i])
	cnt = []
	for j in range(n):
		if j % 2 == 0:
			cnt.append(a[j])
		else:
			cnt.append(1)
	sum1 = 0
	for num in range(n):
		sum1 += abs(a[num] - flag[num])
	if 2 * sum1 <= sum(a):
		print(*flag)
	else:
		print(*cnt)


def check(n, a, b, s):
	z = 0
	for i in range(n):
		z += abs(a[i] - b[i])
	return 2 * z <= s
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = sum(a)
	b = a[:]
	b[::2] = [1] * len(b[::2])
	if check(n, a, b, s):
		print(*b)
	else:
		b = a[:]
		b[1::2] = [1] * len(b[1::2])
		if check(n, a, b, s):
			print(*b)
		else:
			raise Exception('invalid assumption')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a) / 2
	(b1, b2) = ([1] * n, [1] * n)
	for i in range(0, n, 2):
		b1[i] = a[i]
	for i in range(1, n, 2):
		b2[i] = a[i]
	check = 0
	for i in range(n):
		check += abs(a[i] - b1[i])
	if check <= s:
		print(*b1)
		continue
	check = 0
	for i in range(n):
		check += abs(a[i] - b2[i])
	if check <= s:
		print(*b2)
		continue
	while True:
		a = 2


import fractions

def lcm(x, y):
	return x * y // fractions.gcd(x, y)
import math

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

def factorization_expand(n):
	l = factorization(n)
	dat = []
	for (a, b) in l:
		dat += [a] * b
	return dat
from pprint import pprint
import sys

def do():
	n = int(input())
	dat = list(map(int, input().split()))
	s = sum(dat)
	res = []
	cur = dat[0]
	for i in range(n):
		v = math.floor(math.log2(dat[i]))
		(x, y) = (2 ** v, 2 ** (v + 1))
		if abs(dat[i] - x) < abs(dat[i] - y):
			res.append(x)
		elif y > 10 ** 9:
			res.append(y // 2)
		else:
			res.append(y)
	t = 0
	for i in range(n):
		t += abs(dat[i] - res[i])
	print(' '.join(list(map(str, res))))
q = int(input())
for _ in range(q):
	do()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:]
	oddsum = sum(a[::2])
	s = sum(a)
	if oddsum >= s // 2:
		for i in range(1, n, 2):
			b[i] = 1
	else:
		for i in range(0, n, 2):
			b[i] = 1
	print(*b)


import math
for test in range(int(input())):
	int(input())
	a = list(map(int, input().split()))
	b = []
	for el in a:
		b.append(math.floor(math.pow(2, math.floor(math.log2(el)))))
	print(*b)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s_odd = 0
	s_even = 0
	s = sum(a)
	for i in range(n):
		if i % 2 == 0:
			s_odd += a[i]
		else:
			s_even += a[i]
	if s_odd <= s // 2:
		for i in range(n):
			if i % 2 == 0:
				a[i] = 1
	else:
		for i in range(n):
			if i % 2 != 0:
				a[i] = 1
	print(*a)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, sqrt, factorial, cos, tan, sin, radians, floor, ceil, log2
import bisect
from decimal import *
getcontext().prec = 8
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		s = sum(a)
		l1 = []
		l2 = []
		for i in range(n):
			if i % 2:
				l1.append(a[i])
				l2.append(1)
			else:
				l1.append(1)
				l2.append(a[i])
		c = 0
		b = 0
		for i in range(n):
			c += abs(l1[i] - a[i])
			b += abs(l2[i] - a[i])
		b *= 2
		c *= 2
		if b <= s:
			print(*l2)
		else:
			print(*l1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	lst1 = []
	s = sum(lst)
	ind = 0
	c = 0
	while True:
		if ind > n - 1:
			break
		else:
			if c % 2 == 0:
				lst1.append(1)
			else:
				lst1.append(lst[ind])
			ind += 1
			c += 1
	s1 = 0
	for j in range(n):
		s1 += abs(lst[j] - lst1[j])
	if 2 * s1 <= s:
		print(*lst1)
	else:
		lst1 = []
		s = sum(lst)
		ind = 0
		c = 0
		while True:
			if ind > n - 1:
				break
			else:
				if c % 2 != 0:
					lst1.append(1)
				else:
					lst1.append(lst[ind])
				ind += 1
				c += 1
		print(*lst1)


from math import log
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(*[2 ** int(log(a[i], 2)) for i in range(n)])


T_ON = 1
DEBUG_ON = 0
MOD = 998244353

def solve():
	n = read_int()
	A = read_ints()
	odd = 0
	even = 0
	for (i, x) in enumerate(A):
		if i % 2:
			odd += x
		else:
			even += x
	B = A[:]
	for i in range(n):
		if odd < even and i % 2 == 1:
			B[i] = 1
		elif even <= odd and i % 2 == 0:
			B[i] = 1
	print_nums(B)

def solve2():
	A = read_ints()
	A.sort()
	(a, b, c) = A
	x = b - a + c - a
	(q, r) = divmod(x, 7)
	debug(a, b, c, x, q, r)
	a -= q
	if r:
		if (6 - r) % 3 != 0:
			NO()
			return
		else:
			a -= (6 - r) // 2 + 1
	if a >= 0 and a % 3 == 0:
		YES()
	else:
		NO()

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


for _ in range(int(input())):
	n = map(int, input().split())
	a = list(map(int, input().split()))
	c = 1
	i = 0
	while c <= 1000000000:
		d = 2 * c
		if c <= a[i] <= d:
			print(c, end=' ')
			i += 1
			d = 1
		if i == len(a):
			break
		c = d
	print('')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(input())
	list1 = list(map(int, stdin.readline().split()))
	list2 = [1]
	suno1 = list1[0] - 1
	for h in range(1, n):
		if h % 2 != 0:
			list2.append(list1[h])
		else:
			list2.append(1)
			suno1 += abs(list1[h] - 1)
	suno2 = 0
	list3 = [list1[0]]
	for m in range(1, n):
		if m % 2 == 0:
			list3.append(list1[m])
		else:
			list3.append(1)
			suno2 += abs(list1[m] - 1)
	if suno2 <= suno1:
		print(*list3)
	else:
		print(*list2)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [1] * n
	c = [1] * n
	s = sum(a)
	for i in range(n):
		if i % 2:
			b[i] = a[i]
		else:
			c[i] = a[i]
	if 2 * sum((abs(a[i] - b[i]) for i in range(n))) <= s:
		print(*b)
	else:
		print(*c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			even += a[i]
		else:
			odd += a[i]
	b = [0] * n
	if even > odd:
		i = 0
	else:
		i = 1
	for j in range(i, n, 2):
		b[j] = a[j]
	for i in range(n):
		if b[i] == 0:
			print(1, end=' ')
		else:
			print(b[i], end=' ')
	print()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	s = sum(arr)
	sarr = ['1'] * n
	x = sum((arr[i] for i in range(0, n, 2)))
	y = sum((arr[i] for i in range(1, n, 2)))
	if x > y:
		for i in range(0, n, 2):
			sarr[i] = str(arr[i])
	else:
		for i in range(1, n, 2):
			sarr[i] = str(arr[i])
	print(' '.join(sarr))


import math, sys
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		(a, b) = ([], [])
		total = 0
		for i in range(n):
			total += l[i]
			if i % 2 == 0:
				a.append(l[i])
				b.append(1)
			else:
				a.append(1)
				b.append(l[i])
		su = 0
		su1 = 0
		for i in range(n):
			su += abs(a[i] - l[i])
			su1 += abs(b[i] - l[i])
		if su * 2 <= total:
			print(*a)
		else:
			print(*b)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math

def solve():
	n = int(input())
	nrr = list(map(int, input().split()))
	for i in nrr:
		p = int(math.log2(i))
		ans = 2 ** p
		print(ans, end=' ')
for _ in range(int(input())):
	solve()


def find(b, a):
	s = 0
	s1 = sum(b)
	for i in range(len(b)):
		s += abs(a[i] - b[i])
	if 2 * s <= s1:
		return True
	return False
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [1] * n
	p = [1] * n
	for j in range(0, n, 2):
		b[j] = a[j]
	for j in range(1, n, 2):
		p[j] = a[j]
	if find(a, b):
		print(*b)
	else:
		print(*p)


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = [0] * T
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = [0] * n
	for i in range(n):
		B[i] = 1 << A[i].bit_length() - 1
	print(*B)


import math
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	(o, e) = (0, 0)
	for i in range(n):
		if i % 2:
			o += a[i]
		else:
			e += a[i]
	if o > e:
		for i in range(n):
			if i % 2 == 0:
				a[i] = 1
	else:
		for i in range(n):
			if i % 2:
				a[i] = 1
	print(*a, sep=' ')