Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal.

For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}.

The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1.

For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it.

------ Input Format ------ 

- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the number of shops.
- The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop.

------ Output Format ------ 

For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed.

------ Constraints ------ 

$1 ≤ T ≤ 10000$
$2 ≤ N ≤ 2 \cdot 10^{5}$
$0 ≤ A_{i} ≤ 10^{9}$
- The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------ 
2
5
29 412 671 255 912
6
166 94 184 114 1124 298
----- Sample Output 1 ------ 
28 156 159 159 144 
6 24 48 96 96 32 

----- explanation 1 ------ 
Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below:

For shop $1$, choose subarray $[29, 412, 671, 255]$

For shop $2$, choose subarray $[412, 671, 255]$

For shop $3$, choose subarray $[671, 255]$

For shop $4$. choose subarray $[671, 255]$

For shop $5$, choose subarray $[412, 671, 255, 912]$

Difficulty: MEDIUM_HARD
Tags: Bit manipulation
Skill types: Bit manipulation

Starter code:

Solutions:
def ans(arr):
	new_arr = []
	i = 0
	while i < len(arr):
		if i == 0:
			new_arr.append(arr[i] & arr[i + 1])
		elif i == len(arr) - 1:
			new_arr.append(arr[i] & arr[i - 1])
		else:
			new_arr.append(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]))
		i += 1
	return new_arr
test_cases = int(input())
while test_cases != 0:
	d = input()
	d2 = list(map(int, input().split()))
	print(*ans(d2))
	test_cases -= 1


from typing import List

def soln(n: int, arr: List[int]) -> List[int]:
	res = [arr[0] & arr[1]]
	for i in range(1, n - 1):
		res.append(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]))
	res.append(arr[-1] & arr[-2])
	return res
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(*soln(n, arr))


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	arr = [0] * N
	for i in range(N - 1):
		v = A[i] & A[i + 1]
		v1 = v
		vi = i + 1
		for j in range(i, N):
			v1 = arr[j] & v1
			arr[j] = max(arr[j], v1)
			if v1 > v:
				v = v1
				vi = j
			else:
				break
		for j in range(i, vi + 1):
			arr[j] = max(arr[j], v)
	print(*arr)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	ans = list()
	nm = 0
	for i in range(n):
		if i == 0:
			nm = lst[0] & lst[1]
		elif i == n - 1:
			nm = lst[i] & lst[i - 1]
		else:
			nm = max(lst[i] & lst[i - 1], lst[i] & lst[i + 1])
		ans.append(nm)
	print(*ans)


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

def string_list():
	return list(map(str, input().split()))

def hetro_list():
	return list(input().split())

def solve():
	res = print(lst[0] & lst[1], end=' ')
	for i in range(1, n - 1):
		xafter = lst[i] & lst[i + 1]
		xprev = lst[i] & lst[i - 1]
		if xafter < xprev:
			print(xprev, end=' ')
		else:
			print(xafter, end=' ')
	print(lst[-2] & lst[-1])
t = int(input())
for _ in range(t):
	n = int(input())
	lst = integer_list()
	solve()


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

def string_list():
	return list(map(str, input().split()))

def hetro_list():
	return list(input().split())
import math
from collections import Counter

def solve():
	res = [lst[0] & lst[1]]
	for i in range(1, n - 1):
		xafter = lst[i] & lst[i + 1]
		xprev = lst[i] & lst[i - 1]
		if xafter < xprev:
			res.append(xprev)
		else:
			res.append(xafter)
	res.append(lst[-2] & lst[-1])
	print(*res)
t = int(input())
for _ in range(t):
	n = int(input())
	lst = integer_list()
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0] * n
	ans[0] = arr[0] & arr[1]
	ans[n - 1] = arr[n - 1] & arr[n - 2]
	for i in range(1, n - 1):
		ans[i] = max(arr[i] & arr[i + 1], arr[i] & arr[i - 1])
	print(*ans)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	for i in range(n):
		if i == 0:
			print(arr[0] & arr[1], sep='', end=' ')
		elif i == n - 1:
			print(arr[n - 2] & arr[n - 1], sep='', end=' ')
		else:
			print(max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]), sep='', end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if i == 0:
			print(a[i] & a[i + 1], end=' ')
		elif i == n - 1:
			print(a[i] & a[i - 1])
		else:
			print(max(a[i] & a[i + 1], a[i] & a[i - 1]), end=' ')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = []
	for i in range(n):
		if i == 0:
			print(arr[0] & arr[1], end=' ')
		elif i == n - 1:
			print(arr[n - 1] & arr[n - 2], end=' ')
		else:
			print(max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]), end=' ')
	print()


T = int(input())
while T:
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if i == 0:
			print(arr[i] & arr[i + 1], end=' ')
			continue
		if i == n - 1:
			print(arr[i] & arr[i - 1], end=' ')
			continue
		print(max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]), end=' ')
	print()
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	b = []
	x = int(a[0]) & int(a[1])
	y = int(a[n - 2]) & int(a[n - 1])
	b.insert(0, x)
	b.insert(n - 1, y)
	for j in range(1, n - 1):
		c = int(a[j - 1]) & int(a[j])
		d = int(a[j]) & int(a[j + 1])
		e = max(c, d)
		b.insert(j, e)
	g = ' '.join((str(element) for element in b))
	print(g)


for _ in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().strip().split(' ')]
	ans = []
	for i in range(n):
		if i == 0:
			ans.append(A[i] & A[i + 1])
		elif i == n - 1:
			ans.append(A[i] & A[i - 1])
		else:
			ans.append(max(A[i] & A[i + 1], A[i] & A[i - 1]))
	for ele in ans:
		print(ele, end=' ')
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	for i in range(len(a)):
		if i == 0:
			print(a[i] & a[i + 1], end=' ')
			continue
		if i == n - 1:
			print(a[i] & a[i - 1], end=' ')
			continue
		print(max(a[i] & a[i + 1], a[i] & a[i - 1]), end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	for i in range(0, n):
		if i == 0:
			print(lst[i] & lst[i + 1], end=' ')
			continue
		elif i == n - 1:
			print(lst[i] & lst[i - 1])
			continue
		print(max(lst[i] & lst[i + 1], lst[i] & lst[i - 1]), end=' ')


def solve(A, N):
	ans = [0] * N
	ans[0] = A[0] & A[1]
	ans[N - 1] = A[N - 1] & A[N - 2]
	for i in range(1, N - 1):
		ans[i] = max(A[i] & A[i + 1], A[i] & A[i - 1])
	for i in ans:
		print(i, end=' ')
	print()
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	solve(A, N)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		(t, t1) = (0, 0)
		if i - 1 >= 0:
			t = l[i] & l[i - 1]
		if i + 1 < n:
			t1 = l[i] & l[i + 1]
		print(max(t, t1), end=' ')
	print()


t = int(input())
for _ in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	for i in range(0, n):
		if i == 0:
			ans.append(l[i] & l[i + 1])
		elif i == n - 1:
			ans.append(l[i] & l[i - 1])
		else:
			p = 0
			p = max(l[i] & l[i + 1], l[i] & l[i - 1])
			ans.append(p)
	print(*ans[0:])


T = int(input())
for m in range(T):
	n = [int(X) for X in input().split()]
	arr = [int(X) for X in input().split()]
	left = 0
	right = 0
	for i in range(n[0]):
		if i - 1 >= 0:
			left = arr[i] & arr[i - 1]
		if i + 1 < n[0]:
			right = arr[i] & arr[i + 1]
		print(max(left, right), end=' ')
	print()


case = int(input())
for r in range(case):
	n = int(input())
	arr = [int(x) for x in input().split()]
	for i in range(n):
		res = 1
		if i == 0:
			res = arr[0] & arr[1]
			print(res, end=' ')
			continue
		elif i == n - 1:
			res = arr[n - 1] & arr[n - 2]
			print(res, end=' ')
			continue
		else:
			a = arr[i] & arr[i - 1]
			b = arr[i] & arr[i + 1]
			print(max(a, b), end=' ')
	print()


for _ in range(int(input())):
	l = int(input())
	arr = list(map(int, input().strip().split()))
	for i in range(len(arr)):
		(ans1, ans2) = (0, 0)
		if i - 1 >= 0:
			ans1 = arr[i] & arr[i - 1]
		if i + 1 < len(arr):
			ans2 = arr[i] & arr[i + 1]
		print(max(ans1, ans2), end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	c = []
	a = list(map(int, input().split()))
	c.append(a[0] & a[1])
	for i in range(1, n - 1):
		b = a[i] & a[i + 1]
		e = a[i] & a[i - 1]
		c.append(max(b, e))
	c.append(a[n - 1] & a[n - 2])
	print(*c, sep=' ')


t = int(input())
while t > 0:
	n = int(input())
	l1 = list(map(int, input().split()))
	print(l1[0] & l1[1], end=' ')
	for i in range(1, n - 1):
		print(max(l1[i] & l1[i + 1], l1[i] & l1[i - 1]), end=' ')
	print(l1[n - 1] & l1[n - 2])
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split()]
	print(lst[0] & lst[1], end=' ')
	for i in range(1, len(lst) - 1):
		print(max(lst[i] & lst[i + 1], lst[i] & lst[i - 1]), end=' ')
	print(lst[n - 1] & lst[n - 2])


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	print(li[0] & li[1], end=' ')
	for i in range(1, len(li) - 1):
		print(max(li[i] & li[i + 1], li[i] & li[i - 1]), end=' ')
	print(li[n - 1] & li[n - 2])


t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	print(A[0] & A[1], end=' ')
	for i in range(1, n - 1):
		print(max(A[i] & A[i - 1], A[i] & A[i + 1]), end=' ')
	print(A[n - 1] & A[n - 2])


for _ in range(int(input())):
	s = int(input())
	lst = [int(t) for t in input().split()]
	print(lst[0] & lst[1], end=' ')
	for j in range(1, s - 1):
		print(max(lst[j] & lst[j - 1], lst[j] & lst[j + 1]), end=' ')
	print(lst[s - 1] & lst[s - 2])


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		coal = list(map(int, input().split()))
		arr = []
		arr.append(coal[0] & coal[1])
		for i in range(1, n - 1):
			maxx = max(coal[i] & coal[i - 1], coal[i] & coal[i + 1])
			arr.append(maxx)
		arr.append(coal[n - 1] & coal[n - 2])
		print(*arr)
except:
	pass


try:
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		res = []
		res = [a[0] & a[1]]
		for i in range(1, n - 1, 1):
			ans = max(a[i] & a[i - 1], a[i] & a[i + 1])
			res.append(ans)
		res.append(a[-1] & a[-2])
		print(*res)
except:
	pass


t = int(input())
for p in range(t):
	q = int(input())
	b = list(map(int, input().split()))
	b.insert(0, 0)
	b.append(0)
	n = len(b)
	a = b[1] & b[2]
	for i in range(1, len(b) - 1):
		d = a
		a = b[i] & b[i + 1]
		if d > a:
			print(d, end=' ')
		else:
			print(a, end=' ')
	print()


t = int(input())
for p in range(t):
	q = int(input())
	b = list(map(int, input().split()))
	n = len(b)
	for i in range(n):
		val = 0
		if i > 0:
			val = max(val, b[i] & b[i - 1])
		if i < n - 1:
			val = max(val, b[i] & b[i + 1])
		print(val, end=' ')
	print()


tt = int(input())
for _ in range(tt):
	N = int(input())
	n1 = list(map(int, input().split()))
	u = len(n1)
	t = []
	n1.insert(0, 0)
	for i in range(1, u):
		an = max(n1[i] & n1[i + 1], n1[i] & n1[i - 1])
		t.append(an)
	t.append(n1[-2] & n1[-1])
	print(*t)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if i == 0:
			print(arr[0] & arr[1], end=' ')
			continue
		if i == n - 1:
			print(arr[-1] & arr[-2], end=' ')
			continue
		print(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]), end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.insert(0, 0)
	arr.append(0)
	for i in range(1, n + 1):
		print(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]), end=' ')
	print()


try:
	times = int(input())
	for i in range(times):
		x = int(input())
		arr = list(map(int, input().split(' ')))
		maximum = 1
		n = len(arr)
		print(arr[0] & arr[1], end=' ')
		for i in range(1, n - 1):
			maxi = max(arr[i] & arr[i - 1], arr[i] & arr[i + 1])
			print(maxi, end=' ')
		print(arr[n - 2] & arr[n - 1])
except:
	pass


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [a[0] & a[1]]
	for i in range(1, n - 1):
		ans.append(max(a[i] & a[i - 1], a[i] & a[i + 1]))
	ans.append(a[-1] & a[-2])
	for i in ans:
		print(i, end=' ')
	print()


import sys, functools, collections, heapq
input = lambda : sys.stdin.readline()
alp = 'abcdefghijklmnopqrstuvwxyz'

def isValidIndex(x, y, n):
	return x >= 0 and x < n and (y >= 0) and (y < n)

class ListOverride(list):

	def __lt__(self, other):
		return self[1] < other[1]

class Solution:

	def minimumCostPath(self, grid):
		(dx, dy, n) = ([0, 0, -1, 1], [-1, 1, 0, 0], len(grid))
		dist = [[10 ** 9] * n for i in range(n)]
		(dist[0][0], visited, minheap) = (grid[0][0], set(), list())
		heapq.heappush(minheap, ListOverride([(0, 0), grid[0][0]]))
		while len(minheap) > 0:
			pt_cost = heapq.heappop(minheap)
			if pt_cost[0] not in visited:
				visited.add(pt_cost[0])
				(x, y) = pt_cost[0]
				for i in range(4):
					(x1, y1) = (x + dx[i], y + dy[i])
					if isValidIndex(x1, y1, n):
						if dist[x1][y1] > pt_cost[1] + grid[x1][y1]:
							dist[x1][y1] = pt_cost[1] + grid[x1][y1]
							heapq.heappush(minheap, ListOverride([(x1, y1), dist[x1][y1]]))
		return dist[n - 1][n - 1]

	def minPathSum(self, arr):
		(m, n) = (len(arr), len(arr[0]))
		sol = [[0] * n for r in range(m)]
		sol[0][0] = arr[0][0]
		for i in range(1, n):
			sol[0][i] = arr[0][i] + sol[0][i - 1]
		for i in range(1, m):
			sol[i][0] = arr[i][0] + sol[i - 1][0]
		for i in range(1, m):
			for j in range(1, n):
				sol[i][j] = arr[i][j] + min(sol[i - 1][j], sol[i][j - 1])
		return sol[m - 1][n - 1]

	def uniquePaths(self, r, c):
		dp = [[None for i in range(c)] for j in range(r)]
		for j in range(c):
			dp[0][j] = 1
		for i in range(r):
			dp[i][0] = 1
		for i in range(1, r):
			for j in range(1, c):
				dp[i][j] = dp[i][j - 1] + dp[i - 1][j]
		return dp[r - 1][c - 1]

	def lengthOfLIS(self, arr):
		n = len(arr)
		ans = [1] * n
		for i in range(1, n):
			subans = [ans[k] for k in range(i) if arr[k] < arr[i]]
			ans[i] = 1 + max(subans, default=0)
		return max(ans, default=0)

	def knapSack01(self, W, wt, val, n):
		dp = [0 for i in range(W + 1)]
		for i in range(1, n + 1):
			for w in range(W, 0, -1):
				if wt[i - 1] <= W:
					dp[w] = max(dp[w], dp[w - wt[i - 1]] + val[i - 1])
		return dp[W]

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(1, n + 1):
		res = -1000000000000000.0
		if i - 2 >= 0:
			res = max(res, a[i - 1] & a[i - 2])
		if i < n:
			res = max(res, a[i - 1] & a[i])
		print(res, end=' ')
	print()

def main():
	tcs = int(input())
	for tc in range(tcs):
		solve()
main()


import sys

def solve(n, values):
	for i in range(n):
		val = 0
		if i > 0:
			val = max(val, values[i] & values[i - 1])
		if i < n - 1:
			val = max(val, values[i] & values[i + 1])
		print(val, end=' ')
	print()

def main():
	test_case = int(sys.stdin.readline())
	for tc in range(test_case):
		n = int(sys.stdin.readline())
		values = [int(a) for a in sys.stdin.readline().split()]
		solve(n, values)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	for i in range(n):
		if i == 0:
			l.append(a[i] & a[i + 1])
		elif i == n - 1:
			l.append(a[i] & a[i - 1])
		else:
			l.append(max(a[i] & a[i - 1], a[i] & a[i + 1]))
	print(*l)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = []
	res.append(arr[0] & arr[1])
	for i in range(1, n - 1):
		res.append(max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]))
	res.append(arr[-1] & arr[-2])
	print(*res)


try:
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		print(a[0] & a[1], end=' ')
		for i in range(1, n - 1):
			print(max(a[i] & a[i - 1], a[i] & a[i + 1]), end=' ')
		print(a[n - 1] & a[n - 2])
except:
	pass


for q in range(int(input())):
	n = int(input())
	li = [int(x) for x in input().split()]
	for i in range(n):
		if i == 0:
			print(li[i] & li[i + 1], end=' ')
		elif i == n - 1:
			print(li[i - 1] & li[i], end=' ')
		else:
			print(max(li[i] & li[i + 1], li[i - 1] & li[i]), end=' ')
	print()


t = int(input())
for _ in range(t):
	input()
	xs = [int(w) for w in input().strip().split(' ')]
	ans = []
	for (i, x) in enumerate(xs):
		if i == 0:
			ans.append(x & xs[1])
		elif i == len(xs) - 1:
			ans.append(x & xs[i - 1])
		else:
			ans.append(max(x & xs[i - 1], x & xs[i + 1]))
	print(' '.join([str(v) for v in ans]))


for _ in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	for i in range(n):
		if i == 0:
			print(c[i] & c[i + 1], end=' ')
		elif i == n - 1:
			print(c[i - 1] & c[i])
		else:
			print(max(c[i] & c[i + 1], c[i - 1] & c[i]), end=' ')


def maxDamage(n):
	global e
	if n == 0:
		return a[0] & a[1]
	elif n == len(a) - 1:
		return a[n] & a[n - 1]
	else:
		return max(a[n] & a[n - 1], a[n] & a[n + 1])
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	for i in range(len(a)):
		maxi = maxDamage(i)
		res.append(maxi)
	print(*res)


try:
	t = int(input())
	while t != 0:
		n = int(input())
		arr = [int(i) for i in input().split()]
		s = []
		s.append(arr[0] & arr[1])
		for i in range(1, len(arr) - 1):
			s.append(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]))
		s.append(arr[-1] & arr[-2])
		print(*s)
		t -= 1
except EOFError:
	pass


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] + [int(i) for i in input().split()] + [0]
	for i in range(1, n + 1):
		print(max(a[i] & a[i - 1], a[i] & a[i + 1]), end=' ')
	print()


for _ in range(int(input())):
	(n, l) = (int(input()), list(map(int, input().split())))
	l1 = []
	for x in range(n):
		if x == 0:
			l1.append(l[x] & l[x + 1])
		elif x == n - 1:
			l1.append(l[x] & l[x - 1])
		else:
			l1.append(max(l[x] & l[x + 1], l[x] & l[x - 1]))
	print(*l1)


def DhuaDhua(c, n):
	if n == 0:
		return c[0] & c[1]
	elif n == len(c) - 1:
		return c[n] & c[n - 1]
	else:
		return max(c[n] & c[n - 1], c[n] & c[n + 1])
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	ans = []
	for i in range(n):
		ans.append(DhuaDhua(c, i))
	print(*ans)


for _ in range(int(input())):
	m = int(input())
	a = list(map(int, input().split()))
	for n in range(m):
		if n == 0:
			print(a[0] & a[1], end=' ')
		elif n == len(a) - 1:
			print(a[n] & a[n - 1], end=' ')
		else:
			print(max(a[n] & a[n - 1], a[n] & a[n + 1]), end=' ')
	print()


n = int(input())
for i in range(n):
	k = int(input())
	l = list(map(int, input().strip().split(' ')))
	if k == 2:
		print(l[0] & l[1])
		continue
	print(l[0] & l[1], end=' ')
	for i in range(1, len(l) - 1):
		print(max(l[i] & l[i - 1], l[i] & l[i + 1]), end=' ')
	print(l[len(l) - 1] & l[len(l) - 2])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, list(input().split())))
	b = len(l)
	for i in range(b):
		if i == 0:
			print(l[i] & l[i + 1], end=' ')
		elif i != b - 1:
			v = l[i] & l[i + 1]
			k = l[i] & l[i - 1]
			if v > k:
				print(v, end=' ')
			else:
				print(k, end=' ')
		else:
			print(l[i] & l[i - 1], end=' ')
	print()


for _ in range(int(input())):
	(_, l, res, ps) = (int(input()), [int(x) for x in input().split()], [], 0)
	for x in range(_ - 1):
		(sol, ps) = (res.append(max(ps, l[x] & l[x + 1])), l[x] & l[x + 1])
	print(*res + [l[x] & l[x + 1]])


def func(arr, N):
	ans = [0 for i in range(N)]
	ans[0] = arr[0] & arr[1]
	for i in range(1, N - 1):
		ans[i] = max(arr[i] & arr[i + 1], arr[i] & arr[i - 1])
	ans[-1] = arr[N - 1] & arr[N - 2]
	return ans
T = int(input())
for i in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	print(*func(arr, N))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	for i in range(n):
		l = 0
		g = 0
		if i > 0:
			l = arr[i] & arr[i - 1]
		if i < n - 1:
			g = arr[i] & arr[i + 1]
		ans.append(max(l, g))
	print(*ans)


for _ in range(int(input())):
	no_of_ele = int(input())
	arr = list(map(int, input().split()))
	output_arr = []
	output_arr.append(arr[0] & arr[1])
	for i in range(1, len(arr) - 1):
		output_arr.append(max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]))
	output_arr.append(arr[-1] & arr[-2])
	print(*output_arr)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		s = 0
		if i > 0:
			s = max(s, a[i] & a[i - 1])
		if i < n - 1:
			s = max(s, a[i] & a[i + 1])
		print(s, end=' ')
	print('')