#include <bits/stdc++.h>
using namespace std;
int t, n;
map<int, int>a;
int mex(int x, int y)
{
if (x > 1 && y > 1) return 0;
if (x == 1 && y == 1) return 0;
if (min(x, y) == 0 && max(x, y) != 1) return 1;
if (min(x, y) == 0 && max(x, y) == 1) return 2;
return 0;
}
void check3()
{
vector<int> vec;
int num = 0;
for (int i = 1; i <= 3; i++)
{
if (a[i] > 0)
{
vec.push_back(a[i]);
num++;
}
}
if (num == 3 || num == 0)
{
cout << -1 << endl;
return;
}
if (num == 1)
{
cout << 0 << " " << 0 << endl;
cout << 1 << " " << vec[0] << endl;
return;
}
if (num == 2)
{
cout << 0 << " " << vec[0] << endl;
cout << mex(vec[0], 0) << " " << vec[1] << endl;
return;
}
}
int main()
{
cin >> t;
while (t--)
{
a.clear();
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
if (n == 1)
{
cout << -1 << endl;
continue;
}
else if (n == 2)
{
if (a[1] > 0 && a[2] > 0)
{
cout << a[1] << " " << a[2] << endl;
continue;
}
cout << -1 << endl;
continue;
}
else if (n == 3)
{
check3();
continue;
}
else if (n > 3)
{
vector<int> vec;
int num = 0;
for (int i = n; i >= 5; i --)
{
cout << a[i] << " " << a[i - 1] << endl;
a[i - 1] = mex(a[i], a[i - 1]);
}
for (int i = 1; i <= 4; i ++)
{
if (a[i] > 0)
{
num ++;
vec.push_back(a[i]);
}
}
a[1] = 0;
a[2] = 0;
a[3] = 0;
if (num == 0)
{
cout << 0 << " " << 0 << endl;
a[3] = 1;
check3();
}
else if (num == 1)
{
cout << 0 << " " << 0 << endl;
a[3] = 1;
a[2] = 1;
check3();
}
else if (num == 2)
{
cout << 0 << " " << vec[0] << endl;
a[3] = mex(0, vec[0]);
a[2] = vec[1];
check3();
}
else if (num == 3)
{
cout << vec[0] << " " << vec[1] << endl;
a[3] = mex(vec[0], vec[1]);
a[2] = vec[2];
check3();
}
else if (num == 4)
{
cout << vec[0] << " " << vec[1] << endl;
a[3] = mex(vec[0], vec[1]);
a[2] = vec[2];
a[1] = vec[3];
check3();
}
}
}
return 0;
}
222
这是 2026年2月11日 存档的第 3 版,不是当前版本。查看当前版本