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

Solutions:
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()


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


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()


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 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 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()


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()


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 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()


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())):
	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()


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()


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('')