#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin >> n;
vector<int> a(n);
vector<int> b;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] != -1)b.push_back(i);
}
if(b.size() == 0){
if(a[0] == -1){
int t = 1;
for(int i = 0; i < n; i++){
cout << t << " ";
t = (t == 2 ? 1 : 2);
}
cout << "\n";
return;
}
for(int i = 0; i < n - 1; i++){
if(a[i] != a[i + 1] / 2 || a[i + 1] != a[i] / 2){
cout << -1 << "\n";
return;
}
}
for(auto x: a)cout << x << " ";
cout << "\n";
return;
}
int idx = b[0] - 1;
while(idx >= 0){
if(a[idx + 1] > 1)a[idx] = a[idx + 1] / 2;
else a[idx] = 2;
idx--;
}
idx = b.back() + 1;
while(idx < n){
if(a[idx - 1] == 1)a[idx] = 2;
else a[idx] = a[idx - 1] / 2;
idx++;
}
for(int i = 0; i < (int)b.size() - 1; i++){
multiset<pair<int, int>> s;
s.insert({a[b[i]], 0});
s.insert({a[b[i + 1]], 1});
int idx1 = b[i] + 1;
int idx2 = b[i + 1] - 1;
while(s.size() && idx1 <= idx2){
auto [x, y] = *(s.rbegin());
s.erase(s.find({x, y}));
if(y == 0){
if(x == 1)a[idx1] = 2;
else a[idx1] = x / 2;
s.insert({a[idx1], 0});
idx1++;
}else{
if(x == 1)a[idx2] = 2;
else a[idx2] = x / 2;
s.insert({a[idx2], 1});
idx2--;
}
}
}
for(int i = 0; i < n - 1; i++){
if(a[i] != (a[i + 1] / 2) && a[i + 1] != (a[i] / 2)){
cout << -1 << "\n";
return;
// break;
}
}
for(auto x: a)cout << x << " ";
cout << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc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