82 lines
1.2 KiB
C++
82 lines
1.2 KiB
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
void test_case(int tc){
|
|
int n;
|
|
cin >> n;
|
|
|
|
if(n == 1){
|
|
cout << "-1\n";
|
|
return;
|
|
}
|
|
|
|
vector<int> p(n);
|
|
array<bool, 10> numbers;
|
|
|
|
for(int i = 1; i < 10; ++i){
|
|
numbers[i] = false;
|
|
}
|
|
|
|
for(int i = 0; i < n; ++i){
|
|
cin >> p[i];
|
|
numbers[p[i]] = true;
|
|
}
|
|
|
|
vector<int> result;
|
|
|
|
for(int i = 0; i < n - 2; ++i){
|
|
for(int j = 1; j < 10; ++j){
|
|
if(j != p[i] && numbers[j]){
|
|
numbers[j] = false;
|
|
result.push_back(j);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int a, b;
|
|
for(int j = 1; j < 10; ++j){
|
|
if(numbers[j]){
|
|
a = j;
|
|
numbers[j] = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for(int j = 1; j < 10; ++j){
|
|
if(numbers[j]){
|
|
b = j;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(a == p[n - 2]){
|
|
swap(a, b);
|
|
}
|
|
|
|
result.push_back(b);
|
|
result.push_back(a);
|
|
|
|
for(int i : result){
|
|
cout << i << " ";
|
|
} cout << '\n';
|
|
}
|
|
|
|
|
|
|
|
int main(){
|
|
ios::sync_with_stdio(0);
|
|
cin.tie(0);
|
|
|
|
int t;
|
|
cin >> t;
|
|
|
|
for(int tc = 1; tc <= t; ++tc){
|
|
test_case(tc);
|
|
}
|
|
|
|
cout << flush;
|
|
|
|
return 0;
|
|
} |