#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;
}