#include using namespace std; #define ll long long #define endl '\n' ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} void solve() { int n; cin>>n; vectorv(n); for(auto &i:v) cin>>i; int prev=-1; for(int i=0; i=0; --j) { if(v[j+1]>1) v[j]=v[j+1]/2; else v[j]=v[j+1]*2; } prev=i; continue; } int l=prev, r=i; while(r-l>1) { if(v[r]>v[l]) { v[r-1]=v[r]/2; r--; } else { if(v[l]>1) v[l+1]=v[l]/2; else v[l+1]=v[l]*2; l++; } } prev=i; } if(prev1) v[i]=v[i-1]/2; else v[i]=v[i-1]*2; } } for(int i=0; i> TCS; for (int TC = 1; TC <= TCS; ++TC) { // cout<<"Case "<