---
{"category_name":"easy","problem_code":"MAXDMGE","problem_name":"Maximum Damage","problemComponents":{"constraints":"- $1 \\leq T \\leq 10000$\n- $2 \\leq N \\leq 2 \\cdot 10^5$\n- $0 \\leq A_i \\leq 10^9$\n- The sum of $N$ over all test cases does not exceed $2 \\cdot 10^5$.","constraintsState":true,"subtasks":"- 30 points : $1 \\leq R \\leq 10000$\n- 70 points : $1 \\leq R \\leq 10^9$\n","subtasksState":false,"inputFormat":"- The first line of input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$, denoting the number of shops.\n- 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.\n","inputFormatState":true,"outputFormat":"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.\n\n","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"2\n5\n29 412 671 255 912\n6\n166 94 184 114 1124 298","output":"28 156 159 159 144 \n6 24 48 96 96 32 \n","explanation":"**Test case 1:** There are several choices of subarray which give the maximum for each index. One such choice is given below:\n\nFor shop $1$, choose subarray $[29, 412, 671, 255]$\n\nFor shop $2$, choose subarray $[412, 671, 255]$\n\nFor shop $3$, choose subarray $[671, 255]$\n\nFor shop $4$. choose subarray $[671, 255]$\n\nFor shop $5$, choose subarray $[412, 671, 255, 912]$","isDeleted":false}}},"video_editorial_url":"","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":0.5,"source_sizelimit":50000,"problem_author":"anshg0711","problem_tester":"","date_added":"24-09-2021","tags":{"0":"anshg0711","1":"bit","2":"csns2021","3":"simple"},"problem_difficulty_level":"Cakewalk","best_tag":"Bit Manipulation","editorial_url":"https://discuss.codechef.com/problems/MAXDMGE","time":{"view_start_date":1635960604,"submit_start_date":1635960604,"visible_start_date":1635960604,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=MAXDMGE","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
Sardar Khan with two of his henchmen are planning to attack $N$ shops of the Qureshi's, lined up closely numbered from $1$ to $N$. Each of the $N$ shops contains some $A_i$ kg of Coal in them. The coal in each shop would amplify the explosion, allowing the flames to reach other shops too.
Unfortunately, all his bombs are in the locker except $1$ and they have lost the key. Sardar asks Nasir to calculate which shop should be attacked for maximum damage.
Net Damage caused due to bombing on the $i_{th}$ shop is dependent on the amount of coal in the shops in a unique way. Net damage caused by the bombing of the $i_{th}$ shop is the value of the $Bitwise &$ of all elements in a given subarray of shops that must include the $i_{th}$ shop. For each shop, Nasir will choose a subarray that maximizes the net damage and has a size greater than $1$. $Bitwise &$ of a subarray is basically defined as $Bitwise &$ of all the coal present in that subarray of shops.
Nasir being illiterate is weak in maths and devising strategies. So you have to help Nasir and tell him the (maximum) net damage for each shop.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>