#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n);
int pivot = -1;
for (int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 1) pivot = i; // 保證至少有一個 1
}
vector<pair<int,int>> moves;
// 向左傳播:使得 0~pivot 的欄均變成 1
for(int i = pivot - 1; i >= 0; i--){
if(a[i] == 1) continue; // 已經固定為 1,不用動
if(a[i] < 1){
// a[i] == 0,鄰欄 a[i+1] 固定為 1
// 允許的操作:從欄 (i+1) 向欄 i 轉移,輸出 1-索引為 (i+2, i+1)
moves.push_back({i+2, i+1});
} else {
// a[i] == 2,鄰欄 a[i+1] 固定為 1
// 允許操作:從欄 i 向欄 (i+1) 轉移,輸出 (i+1, i+2)
moves.push_back({i+1, i+2});
}
a[i] = 1; // 模擬固定該欄為 1
}
// 向右傳播:使得 pivot~(n-1) 的欄均變成 1
for(int i = pivot + 1; i < n; i++){
if(a[i] == 1) continue;
if(a[i] < 1){
// a[i] == 0,鄰欄 a[i-1] 固定為 1
// 允許操作:從欄 (i-1) 向欄 i 轉移,輸出 (i, i+1)
moves.push_back({i, i+1});
} else {
// a[i] == 2,鄰欄 a[i-1] 固定為 1
// 允許操作:從欄 i 向欄 (i-1) 轉移,輸出 (i+1, i)
moves.push_back({i+1, i});
}
a[i] = 1;
}
// 輸出答案
cout << moves.size() << "\n";
for(auto &mv : moves){
cout << mv.first << " " << mv.second << "\n";
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwogCmludCBtYWluKCl7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgCiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICB2ZWN0b3I8aW50PiBhKG4pOwogICAgICAgIGludCBwaXZvdCA9IC0xOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICAgICAgY2luID4+IGFbaV07CiAgICAgICAgICAgIGlmKGFbaV0gPT0gMSkgcGl2b3QgPSBpOyAvLyDkv53orYnoh7PlsJHmnInkuIDlgIsgMQogICAgICAgIH0KICAgICAgICAKICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsaW50Pj4gbW92ZXM7CiAgICAgICAgCiAgICAgICAgLy8g5ZCR5bem5YKz5pKt77ya5L2/5b6XIDDvvZ5waXZvdCDnmoTmrITlnYforormiJAgMQogICAgICAgIGZvcihpbnQgaSA9IHBpdm90IC0gMTsgaSA+PSAwOyBpLS0pewogICAgICAgICAgICBpZihhW2ldID09IDEpIGNvbnRpbnVlOyAvLyDlt7LntpPlm7rlrprngrogMe+8jOS4jeeUqOWLlQogICAgICAgICAgICBpZihhW2ldIDwgMSl7IAogICAgICAgICAgICAgICAgLy8gYVtpXSA9PSAw77yM6YSw5qyEIGFbaSsxXSDlm7rlrprngrogMQogICAgICAgICAgICAgICAgLy8g5YWB6Kix55qE5pON5L2c77ya5b6e5qyEIChpKzEpIOWQkeashCBpIOi9ieenu++8jOi8uOWHuiAxLee0ouW8leeCuiAoaSsyLCBpKzEpCiAgICAgICAgICAgICAgICBtb3Zlcy5wdXNoX2JhY2soe2krMiwgaSsxfSk7CiAgICAgICAgICAgIH0gZWxzZSB7IAogICAgICAgICAgICAgICAgLy8gYVtpXSA9PSAy77yM6YSw5qyEIGFbaSsxXSDlm7rlrprngrogMQogICAgICAgICAgICAgICAgLy8g5YWB6Kix5pON5L2c77ya5b6e5qyEIGkg5ZCR5qyEIChpKzEpIOi9ieenu++8jOi8uOWHuiAoaSsxLCBpKzIpCiAgICAgICAgICAgICAgICBtb3Zlcy5wdXNoX2JhY2soe2krMSwgaSsyfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYVtpXSA9IDE7IC8vIOaooeaTrOWbuuWumuipsuashOeCuiAxCiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vIOWQkeWPs+WCs+aSre+8muS9v+W+lyBwaXZvdO+9nihuLTEpIOeahOashOWdh+iuiuaIkCAxCiAgICAgICAgZm9yKGludCBpID0gcGl2b3QgKyAxOyBpIDwgbjsgaSsrKXsKICAgICAgICAgICAgaWYoYVtpXSA9PSAxKSBjb250aW51ZTsKICAgICAgICAgICAgaWYoYVtpXSA8IDEpewogICAgICAgICAgICAgICAgLy8gYVtpXSA9PSAw77yM6YSw5qyEIGFbaS0xXSDlm7rlrprngrogMQogICAgICAgICAgICAgICAgLy8g5YWB6Kix5pON5L2c77ya5b6e5qyEIChpLTEpIOWQkeashCBpIOi9ieenu++8jOi8uOWHuiAoaSwgaSsxKQogICAgICAgICAgICAgICAgbW92ZXMucHVzaF9iYWNrKHtpLCBpKzF9KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIC8vIGFbaV0gPT0gMu+8jOmEsOashCBhW2ktMV0g5Zu65a6a54K6IDEKICAgICAgICAgICAgICAgIC8vIOWFgeioseaTjeS9nO+8muW+nuashCBpIOWQkeashCAoaS0xKSDovYnnp7vvvIzovLjlh7ogKGkrMSwgaSkKICAgICAgICAgICAgICAgIG1vdmVzLnB1c2hfYmFjayh7aSsxLCBpfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYVtpXSA9IDE7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vIOi8uOWHuuetlOahiAogICAgICAgIGNvdXQgPDwgbW92ZXMuc2l6ZSgpIDw8ICJcbiI7CiAgICAgICAgZm9yKGF1dG8gJm12IDogbW92ZXMpewogICAgICAgICAgICBjb3V0IDw8IG12LmZpcnN0IDw8ICIgIiA8PCBtdi5zZWNvbmQgPDwgIlxuIjsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9