连 B 都写不出来了……
#include <bits/stdc++.h>
using namespace std;
#define MAXN 200001
int t, n, ind1, ind2, ind3;
int a[MAXN];
vector<int> vec;
void print(int x, int y){
swap(a[x], a[y]);
cout << min(x, y) << ' ' << max(x, y) << '\n';
// for (int i(1); i<=n; ++i) cout << a[i] << ' ';
// cout << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--){
cin >> n;
vec.clear();
for (int i(1); i<=n; ++i){
cin >> a[i];
if (a[i] == 1) ind1 = i;
else if (a[i] == 2) ind2 = i;
else if (a[i] == 3) ind3 = i;
else vec.push_back(i);
}
if (abs(ind1-ind2) > 1 && abs(ind1-ind3) > 1){
print(1, 1);
continue;
}
if (n == 3){
if (abs(ind1-ind2) > 1) print(1, 1);
else{
if (ind1 == 2 || ind1 == 1) print(2, 3);
else print(1, 2);
}
continue;
}
int flag(1);
for (auto i: vec){
if (abs(ind2-i) > 1){
print(i, ind1);
flag = 0;
break;
}
}
if (!flag) continue;
if (abs(ind1-ind2) == 1){
if (abs(ind1-ind3) == 1) print(ind1, vec[0]);
else print(1, 1);
}else{
if (abs(ind1-ind3) <= 2 && abs(ind2-ind3) <= 2 && abs(ind1-ind2) <= 2) print(ind3, vec[0]);
else print(1, 1);
}
}
return 0;
}