description: An important meeting is to be held and there are exactly n people invited. At any moment, any two people can step back and talk in private. The same two people can talk several (as many as they want) times per meeting.
  
  Each person has limited sociability. The sociability of the i-th person is a non-negative integer a_i. This means that after exactly a_i talks this person leaves the meeting (and does not talk to anyone else anymore). If a_i = 0, the i-th person leaves the meeting immediately after it starts.
  
  A meeting is considered most productive if the maximum possible number of talks took place during it.
  
  You are given an array of sociability a, determine which people should talk to each other so that the total number of talks is as large as possible.
  
  Input
  
  The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.
  
  The next 2t lines contain descriptions of the test cases.
  
  The first line of each test case description contains an integer n (2 ≤ n ≤ 2 ⋅ 10^5) —the number of people in the meeting. The second line consists of n space-separated integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2 ⋅ 10^5) — the sociability parameters of all people. 
  
  It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. It is also guaranteed that the sum of all a_i (over all test cases and all i) does not exceed 2 ⋅ 10^5.
  
  Output
  
  Print t answers to all test cases.
  
  On the first line of each answer print the number k — the maximum number of talks possible in a meeting.
  
  On each of the next k lines print two integers i and j (1 ≤ i, j ≤ n and i ≠ j) — the numbers of people who will have another talk.
  
  If there are several possible answers, you may print any of them.
  
  Example
  
  Input
  
  
  8
  2
  2 3
  3
  1 2 3
  4
  1 2 3 4
  3
  0 0 2
  2
  6 2
  3
  0 0 2
  5
  8 2 0 1 1
  5
  0 1 0 0 6
  
  
  Output
  
  
  2
  1 2
  1 2
  3
  1 3
  2 3
  2 3
  5
  1 3
  2 4
  2 4
  3 4
  3 4
  0
  2
  1 2
  1 2
  0
  4
  1 2
  1 5
  1 4
  1 2
  1
  5 2
solution: //package codeforces;
  
  import java.io.*;
  import java.util.*;
  
  public class ProblemB {
      private final static FastScanner scanner = new FastScanner();
      private final static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
  
      public static void main(String[] args) throws IOException {
          int n = scanner.nextInt();
          for (int i = 0; i < n; i++) {
              solve();
          }
  //        solve();
      }
  
      public static void solve() throws IOException {
          int n = scanner.nextInt();
          List<int[]> list = new ArrayList<>();
          for (int i = 1; i <= n; i++) {
              int input = scanner.nextInt();
              if (input != 0) {
                  list.add(new int[]{i, input});
              }
          }
          PriorityQueue<int[]> pq = new PriorityQueue<>((o1, o2) -> o2[1] - o1[1]);
          for (int[] ints : list) {
              pq.offer(ints);
          }
          list.clear();
          while (pq.size() > 1){
              int[] first = pq.poll();
              int[] second = pq.poll();
              list.add(new int[]{first[0], second[0]});
              first[1] -= 1;
              second[1] -= 1;
              if(first[1] > 0) pq.offer(first);
              if(second[1] > 0) pq.offer(second);
          }
          System.out.println(list.size());
          for (int[] ints : list) {
              Arrays.sort(ints);
              System.out.println(ints[0] + " " + ints[1]);
          }
      }
  
      private static int getTickSize(char[][] mat, int i, int j) {
          if (i < 0 || j < 0 || i >= mat.length || j >= mat[0].length || mat[i][j] == '.') return 0;
          mat[i][j] = '.';
          return Math.min(getTickSize(mat, i - 1, j - 1), getTickSize(mat, i - 1, j + 1));
      }
  
      private static Boolean isSquare(long x) {
          long y = (long) Math.sqrt(x);
          return y * y == x;
      }
  
      private static int getMax(int[] arr) {
          int[] copy = Arrays.copyOf(arr, arr.length);
          Arrays.sort(copy);
          return copy[arr.length - 1];
      }
  
      private static double customLog(double logNumber, double base) {
          return Math.log(logNumber) / Math.log(base);
      }
  
  
      static int checkSim(String n1, String n2, int i, int j) {
          if (i >= n1.length() || j >= n2.length()) return 0;
          if (n1.charAt(i) == n2.charAt(j)) return 1 + checkSim(n1, n2, i + 1, j + 1);
          return checkSim(n1, n2, i + 1, j);
      }
  
      static int computeXOR(int n) {
          if (n % 4 == 0)
              return n;
          if (n % 4 == 1)
              return 1;
          if (n % 4 == 2)
              return n + 1;
          return 0;
      }
  
      static boolean isPowerOfTwo(long n) {
          if (n == 0)
              return false;
  
          double v = Math.log(n) / Math.log(2);
          return (long) (Math.ceil(v)) == (long) (Math.floor(v));
      }
  
      static boolean isPrime(int n) {
          if (n <= 1)
              return false;
  
          else if (n == 2)
              return true;
  
          else if (n % 2 == 0)
              return false;
  
          for (int i = 3; i <= Math.sqrt(n); i += 2) {
              if (n % i == 0)
                  return false;
          }
          return true;
      }
  
      static boolean checkSorted(int[] arr) {
          for (int i = 1; i < arr.length; i++) {
              if (arr[i - 1] > arr[i]) return false;
          }
          return true;
      }
  
      static void print(int from, int to) {
          if (from <= to) {
              for (int i = from; i <= to; i++) {
                  System.out.print(i + " ");
              }
          } else {
              System.out.print(from + " ");
              for (int i = 1; i <= to; i++) {
                  System.out.print(i + " ");
              }
          }
      }
  
      static long moduloMultiplication(long a, long b, long mod) {
          long res = 0;
          a %= mod;
          while (b > 0) {
              if ((b & 1) > 0) {
                  res = (res + a) % mod;
              }
              a = (2 * a) % mod;
              b >>= 1;
          }
          return res;
      }
  
      static long moduloPower(long x, long y, long p) {
          long res = 1L;
          x = x % p;
          while (y > 0) {
              if ((y & 1) > 0)
                  res = (res * x) % p;
  
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      static long upperBound(long[] arr, int start, int end, long k) {
          int N = end;
          while (start < end) {
              int mid = start + (end - start) / 2;
              if (k >= arr[mid]) {
                  start = mid + 1;
              } else {
                  end = mid;
              }
          }
          if (start < N && arr[start] <= k) {
              start++;
          }
          return start;
      }
  
      static long lowerBound(long[] arr, int start, int end, long k) {
          int N = end;
          while (start < end) {
              int mid = start + (end - start) / 2;
              if (k <= arr[mid]) {
                  end = mid;
              } else {
                  start = mid + 1;
              }
          }
          if (start < N && arr[start] < k) {
              start++;
          }
          return start;
      }
  
      static int getDistance(int x1, int y1, int x2, int y2) {
          return Math.abs(x1 - x2) + Math.abs(y1 - y2);
      }
  
      static int sumOfNNaturalNumbers(int n) {
          return (n * (n + 1)) / 2;
      }
  
      static int gcd(int a, int b) {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
  
  
      static class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          String next() {
              while (!st.hasMoreTokens())
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
      }
  }
  