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: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.File;
  import java.io.*;
  import java.util.*;
  
  public class Main {
  
      // static final File ip = new File("input.txt");
      // static final File op = new File("output.txt");
      // static {
      //     try {
      //         System.setOut(new PrintStream(op));
      //         System.setIn(new FileInputStream(ip));
      //     } catch (Exception e) {
      //     }
      // }
  
      static ArrayList<int[]> as = new ArrayList<>();
  
      static void sort(long arr[]) {
          int n = arr.length;
          for (int i = 1; i < n; ++i) {
              long key = arr[i];
              int j = i - 1;
              boolean check = false;
              while (j >= 0 && arr[j] > key) {
                  arr[j + 1] = arr[j];
                  j = j - 1;
                  check = true;
              }
              if (check == true) {
                  as.add(new int[] { (i - j - 1), (i + 1), i - j - 1 });
              }
              arr[j + 1] = key;
          }
      }
  
      public static void main(String[] args) {
          FastReader sc = new FastReader();
          int test = sc.nextInt();
          while (test-- != 0) {
              int n = sc.nextInt();
              PriorityQueue<pair> pq = new PriorityQueue<>(new comparator());
              ArrayList<long[]> as = new ArrayList<>();
              for (int i = 0; i < n; i++) {
                  long a = sc.nextLong();
                  if (a > 0)
                      pq.add(new pair(i, a));
              }
              while (pq.size() > 1) {
                  pair p1 = pq.poll();
                  pair p2 = pq.poll();
                  long pos1 = p1.a;
                  long pos2 = p2.a;
                  as.add(new long[] { pos1 + 1, pos2 + 1 });
                  p1.b--;
                  p2.b--;
                  if (p1.b > 0)
                      pq.add(p1);
                  if (p2.b > 0)
                      pq.add(p2);
              }
              System.out.println(as.size());
              for (int i = 0; i < as.size(); i++) {
                  long x = as.get(i)[0];
                  long y = as.get(i)[1];
                  System.out.println(x + " " + (y));
              }
          }
      }
  
      static long power(long x, long y, long p) {
          long res = 1;
          x = x % p;
          if (x == 0)
              return 0;
          while (y > 0) {
              if ((y & 1) != 0)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      public static int countSetBits(long number) {
          int count = 0;
          while (number > 0) {
              ++count;
              number &= number - 1;
          }
          return count;
      }
  
      private static <T> void swap(int[] a, int i, int j) {
          int tmp = a[i];
          a[i] = a[j];
          a[j] = tmp;
      }
  
      static class pair {
          long a, b;
  
          pair(long x, long y) {
              this.a = x;
              this.b = y;
          }
  
          public int compare(pair p1, pair p2) {
              if (p1.a - p2.a > 0)
                  return -1;
              if (p1.a - p2.a < 0)
                  return 1;
              return 0;
          }
      }
  
      static class comparator implements Comparator<pair> {
  
          public int compare(pair p1, pair p2) {
              if (p1.b > p2.b)
                  return -1;
              else if (p1.b < p2.b)
                  return 1;
              return 0;
          }
      }
  
      private static long getSum(int[] array) {
          long sum = 0;
          for (int value : array) {
              sum += value;
          }
          return sum;
      }
  
      private static boolean isPrime(Long x) {
          if (x < 2)
              return false;
          for (long d = 2; d * d <= x; ++d) {
              if (x % d == 0)
                  return false;
          }
          return true;
      }
  
      static int[] reverse(int a[], int n) {
          int i, k, t;
          for (i = 0; i < n / 2; i++) {
              t = a[i];
              a[i] = a[n - i - 1];
              a[n - i - 1] = t;
          }
          return a;
      }
  
      private static boolean isPrimeInt(int x) {
          if (x < 2)
              return false;
          for (int d = 2; d * d <= x; ++d) {
              if (x % d == 0)
                  return false;
          }
          return true;
      }
  
      public static String reverse(String input) {
          StringBuilder str = new StringBuilder("");
  
          for (int i = input.length() - 1; i >= 0; i--) {
              str.append(input.charAt(i));
          }
  
          return str.toString();
      }
  
      private static int[] getPrimes(int n) {
          boolean[] used = new boolean[n + 1];
          used[0] = used[1] = true;
          int size = 0;
          for (int i = 2; i <= n; ++i) {
              if (!used[i]) {
                  ++size;
                  for (int j = 2 * i; j <= n; j += i) {
                      used[j] = true;
                  }
              }
          }
          int[] primes = new int[size];
          for (int i = 0, cur = 0; i <= n; ++i) {
              if (!used[i]) {
                  primes[cur++] = i;
              }
          }
          return primes;
      }
  
      private static long lcm(long a, long b) {
          return a / gcd(a, b) * b;
      }
  
      private static long gcd(long a, long b) {
          return (a == 0 ? b : gcd(b % a, a));
      }
  
      static void sortI(int[] arr) {
          int n = arr.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              int tmp = arr[i];
              int randomPos = i + rnd.nextInt(n - i);
              arr[i] = arr[randomPos];
              arr[randomPos] = tmp;
          }
          Arrays.sort(arr);
      }
  
      static void shuffleList(ArrayList<Long> arr) {
          int n = arr.size();
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              long tmp = arr.get(i);
              int randomPos = i + rnd.nextInt(n - i);
              arr.set(i, arr.get(randomPos));
              arr.set(randomPos, tmp);
          }
      }
  
      static void factorize(long n) {
          int count = 0;
          while (!(n % 2 > 0)) {
              n >>= 1;
  
              count++;
          }
          if (count > 0) {
              // System.out.println("2" + " " + count);
          }
          long i = 0;
          for (i = 3; i <= (long) Math.sqrt(n); i += 2) {
              count = 0;
              while (n % i == 0) {
                  count++;
                  n = n / i;
              }
              if (count > 0) {
                  // System.out.println(i + " " + count);
              }
          }
  
          if (n > 2) {
              // System.out.println(i + " " + count);
          }
      }
  
      static void sortL(long[] arr) {
          int n = arr.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              long tmp = arr[i];
              int randomPos = i + rnd.nextInt(n - i);
              arr[i] = arr[randomPos];
              arr[randomPos] = tmp;
          }
          Arrays.sort(arr);
      }
  
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          public boolean hasNext() {
              return false;
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  }