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.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  import java.util.InputMismatchException;
  import java.io.IOException;
  import java.util.TreeSet;
  import java.util.Objects;
  import java.io.Writer;
  import java.io.OutputStreamWriter;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   *
   * @author Roy
   */
  public class Main {
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          OutputWriter out = new OutputWriter(outputStream);
          DProductiveMeeting solver = new DProductiveMeeting();
          solver.solve(1, in, out);
          out.close();
      }
  
      static class DProductiveMeeting {
          public void solve(int testNumber, InputReader in, OutputWriter out) {
              int testCases = in.readInteger();
              for (int cs = 1; cs <= testCases; ++cs) {
                  int n = in.readInteger();
  
                  TreeSet<Pair<Integer, Integer>> s = new TreeSet<>();
                  for (int i = 1; i <= n; i++) {
                      int x = in.readInteger();
                      if (x == 0) continue;
                      s.add(Pair.of(x, i));
                  }
  
                  int count = 0;
                  StringBuilder ans = new StringBuilder();
                  while (s.size() > 1) {
                      count++;
                      Pair<Integer, Integer> max = s.first();
                      Pair<Integer, Integer> min = s.last();
  
                      s.remove(max);
                      s.remove(min);
                      if (max.first - 1 != 0) {
                          max = Pair.of(max.first - 1, max.second);
                          s.add(max);
                      }
                      if (min.first - 1 != 0) {
                          min = Pair.of(min.first - 1, min.second);
                          s.add(min);
                      }
  
                      ans.append(min.second).append(" ").append(max.second).append("\n");
                  }
  
                  out.printLine(count);
                  out.print(ans);
              }
          }
  
      }
  
      static class OutputWriter {
          private final PrintWriter writer;
  
          public OutputWriter(OutputStream outputStream) {
              writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
          }
  
          public OutputWriter(Writer writer) {
              this.writer = new PrintWriter(writer);
          }
  
          public void print(Object... objects) {
              for (int i = 0; i < objects.length; i++) {
                  if (i != 0) {
                      writer.print(' ');
                  }
                  writer.print(objects[i]);
              }
          }
  
          public void printLine(Object... objects) {
              this.print(objects);
              writer.println();
          }
  
          public void close() {
              writer.flush();
              writer.close();
          }
  
      }
  
      static class Pair<F, S> implements Comparable<Pair<F, S>> {
          public F first;
          public S second;
  
          public Pair(F first, S second) {
              this.first = first;
              this.second = second;
          }
  
          public static <F, S> Pair<F, S> of(F first, S second) {
              return new Pair<>(first, second);
          }
  
          public String toString() {
              return "<" + first + ", " + second + ">";
          }
  
          public int hashCode() {
              int hash = 7;
              hash = 31 * hash + (first != null ? first.hashCode() : 0);
              hash = 31 * hash + (second != null ? second.hashCode() : 0);
              return hash;
          }
  
          public boolean equals(Object o) {
              if (this == o) return true;
              if (o instanceof Pair<?, ?>) {
                  Pair<?, ?> pair = (Pair<?, ?>) o;
                  if (!Objects.equals(first, pair.first)) return false;
                  return Objects.equals(second, pair.second);
              }
              return false;
          }
  
          public int compareTo(Pair o) {
              int comparedVal = Integer.compare(this.first.hashCode(), o.first.hashCode());
              if (comparedVal == 0) return Integer.compare(this.second.hashCode(), o.second.hashCode());
              return comparedVal;
          }
  
      }
  
      static class InputReader {
          private int curChar;
          private int numChars;
          private InputReader.SpaceCharFilter filter;
          private final InputStream stream;
          private final byte[] buf = new byte[1024];
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          private long readWholeNumber(int c) {
              long res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res;
          }
  
          public int read() {
              if (numChars == -1) {
                  throw new InputMismatchException();
              }
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
  
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0) {
                      return -1;
                  }
              }
              return buf[curChar++];
          }
  
          public int readInteger() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = (int) readWholeNumber(c);
              return res * sgn;
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null) {
                  return filter.isSpaceChar(c);
              }
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          public interface SpaceCharFilter {
              boolean isSpaceChar(int ch);
  
          }
  
      }
  }
  
  