#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, flag = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-') c = getchar();
  if (c == '-') flag = 0, c = getchar();
  while (c <= '9' && c >= '0') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? x : -x;
}
int n, a[18], inf = 1e8;
int f[16][1 << 15][16], la[16][1 << 15][16][2], sum[1 << 15];
int get(int m) {
  int ret = 0;
  for (int i = 0; i < n; i++)
    if ((1 << i) & m) ret += a[i + 1];
  return ret;
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    for (int i = (1); i <= (int)(n); i++) a[i] = read();
    for (int i = (0); i <= (int)(n); i++)
      for (int j = (0); j <= (int)((1 << n) - 1); j++)
        for (int k = (0); k <= (int)(n); k++)
          f[i][j][k] = inf, la[i][j][k][0] = la[i][j][k][1] = 0;
    for (int j = (0); j <= (int)((1 << n) - 1); j++) sum[j] = get(j);
    f[0][0][0] = 0;
    for (int i = 0; i < n; i++)
      for (int mask = 0; mask < (1 << n); mask++)
        for (int p = i; p < n; p++) {
          if (f[i][mask][p] == inf) continue;
          int mm = ((1 << n) - 1) ^ mask;
          for (int m = mm; m; m = (m - 1) & mm) {
            int mask2 = m | mask;
            if ((m >> p) == 0) continue;
            int p2 = p + __builtin_ctz(m >> p) + 1;
            if (mask & (1 << (p2 - 1))) continue;
            if (sum[m] > f[i][mask][p] && sum[m] < f[i + 1][mask2][p2]) {
              f[i + 1][mask2][p2] = sum[m];
              la[i + 1][mask2][p2][0] = mask;
              la[i + 1][mask2][p2][1] = p;
            }
          }
        }
    int len = 0, mm = (1 << n) - 1, pp = 0;
    for (int i = (1); i <= (int)(n); i++)
      for (int p = (1); p <= (int)(n); p++)
        if (f[i][(1 << n) - 1][p] < inf) len = i, pp = p;
    vector<int> x[n + 1], y;
    for (int l = (len); l >= (1); l--) {
      y.push_back(pp);
      int q = mm ^ la[l][mm][pp][0];
      for (int i = 0; i < n; i++)
        if (((1 << i) & q) && i + 1 != pp) x[pp].push_back(i + 1);
      int p = la[l][mm][pp][1], m = la[l][mm][pp][0];
      pp = p;
      mm = m;
    }
    vector<pair<int, int> > ans;
    for (int q = y.size() - 1, p = y[q]; q >= 0; p = y[(--q) >= 0 ? q : 0])
      for (int i : x[p]) {
        int ii = i, pp = p;
        for (int j = (1); j <= (int)(i - 1); j++)
          if (!a[j]) ii--;
        for (int j = (1); j <= (int)(p - 1); j++)
          if (!a[j]) pp--;
        ans.push_back(make_pair(ii, pp));
        a[p] += a[i];
        a[i] = 0;
      }
    printf("%d\n", ans.size());
    for (pair<int, int> p : ans) printf("%d %d\n", p.first, p.second);
  }
  return 0;
}
