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.DataInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.PriorityQueue;
  
  public class Main {
  	static boolean DEBUG = false;
  
  	public static void main(String[] args) throws IOException {
  		Comparator<person> com = (p1, p2) -> p1.x > p2.x ? -1 : 1;
  		if (System.getProperty("ONLINE_JUDGE") == null) {
  			System.setIn(new FileInputStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//input.txt")));
  			// System.setOut(new PrintStream(new File("output.txt")));
  			System.setErr(new PrintStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//error.txt")));
  			DEBUG = true;
  		}
  		Reader fs = new Reader();
  		PrintWriter pw = new PrintWriter(System.out);
  		int t = fs.nextInt();
  		while (t-- > 0) {
  			int n = fs.nextInt();
  			PriorityQueue<person> pq = new PriorityQueue(n, com);
  			for (int i = 1; i <= n; i++) {
  				int temp = fs.nextInt();
  				if (temp > 0)
  					pq.add(new person(i, temp));
  			}
  			ArrayList<Integer> ans = new ArrayList<Integer>();
  			while (pq.size() > 1) {
  				person p1, p2;
  				p1 = pq.poll();
  				p2 = pq.poll();
  				p1.x--;
  				p2.x--;
  				ans.add(p1.idx);
  				ans.add(p2.idx);
  				if (p1.x > 0) {
  					pq.add(p1);
  				}
  				if (p2.x > 0) {
  					pq.add(p2);
  				}
  			}
  			pw.println(ans.size() / 2);
  			for(int i = 0 ; i < ans.size() ; i += 2) {
  				int x = ans.get(i), y = ans.get(i + 1);
  				pw.println(x + " " + y);
  			}
  		}
  		fs.close();
  		pw.close();
  	}
  
  	static class person {
  		int idx, x;
  
  		person(int idx, int x) {
  			this.idx = idx;
  			this.x = x;
  		}
  	}
  
  	static void debug(int a[], String l) {
  		if (DEBUG) {
  			System.err.print("l-> [");
  			for (int x : a)
  				System.err.print(x + " ");
  			System.err.println("]");
  		}
  	}
  
  	static void debug(long a[], String l) {
  		if (DEBUG) {
  			System.err.print("l-> [");
  			for (long x : a)
  				System.err.print(x + " ");
  			System.err.println("]");
  		}
  	}
  
  	static <T> void debug(HashSet<Integer> a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> ");
  			System.err.println(a);
  		}
  	}
  
  	static void debug(String a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static void debug(StringBuilder a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static <T extends Number, V extends T> void debug(HashMap<T, V> a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> ");
  			System.err.println(a);
  		}
  	}
  
  	static <T extends Number> void debug(T a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static <T extends Number> void debug(T[] a, String l) {
  		if (DEBUG) {
  			System.err.print(l + " -> \n" + "[ ");
  			for (int i = 0; i < a.length; i++) {
  				System.err.print(a[i] + " ");
  			}
  			System.err.println("]");
  		}
  	}
  
  	static <T> void debug(ArrayList<T> a, String l) {
  		if (DEBUG) {
  			System.err.print(l + " -> ");
  			System.err.print("[ ");
  			for (T q : a) {
  				System.err.print(q + " ");
  			}
  			System.err.println("]");
  		}
  	}
  
  	static boolean primeFactors(long n, long b) {
  		while (n % 2 == 0) {
  			if (b % 2 != 0)
  				return false;
  			n = n / 2;
  		}
  		for (long i = 3; i * i <= n; i = i + 2) {
  			while (n % i == 0) {
  				if (b % i != 0)
  					return false;
  				n = n / i;
  			}
  		}
  		if (n > 2)
  			if (b % n != 0)
  				return false;
  		return true;
  	}
  
  	public static long __gcd(long a, long b) {
  		if (b != 0) {
  			return __gcd(b, a % b);
  		} else {
  			return a;
  		}
  	}
  
  	public static int lower_bound(ArrayList<Integer> ar, int k) {
  		int s = 0;
  		int e = ar.size();
  		while (s != e) {
  			int mid = s + e >> 1;
  			if (ar.get(mid) < k) {
  				s = mid + 1;
  			} else {
  				e = mid;
  			}
  		}
  		if (s == ar.size()) {
  			return -1;
  		}
  		return s;
  	}
  
  	public static int upper_bound(ArrayList<Integer> ar, int k) {
  		int s = 0;
  		int e = ar.size();
  		while (s != e) {
  			int mid = s + e >> 1;
  			if (ar.get(mid) <= k) {
  				s = mid + 1;
  			} else {
  				e = mid;
  			}
  		}
  		if (s == ar.size()) {
  			return -1;
  		}
  		return s;
  	}
  
  	static final int MAXN = (int) 1e7;
  
  	// stores smallest prime factor for every number
  	static int spf[] = new int[MAXN];
  
  	// Calculating SPF (Smallest Prime Factor) for every
  	// number till MAXN.
  	// Time Complexity : O(nloglogn)
  	static void sieve() {
  		spf[1] = 1;
  		for (int i = 2; i < MAXN; i++)
  
  			// marking smallest prime factor for every
  			// number to be itself.
  			spf[i] = i;
  
  		// separately marking spf for every even
  		// number as 2
  		for (int i = 4; i < MAXN; i += 2)
  			spf[i] = 2;
  
  		for (int i = 3; i * i < MAXN; i++) {
  			// checking if i is prime
  			if (spf[i] == i) {
  				// marking SPF for all numbers divisible by i
  				for (int j = i * i; j < MAXN; j += i)
  
  					// marking spf[j] if it is not
  					// previously marked
  					if (spf[j] == j)
  						spf[j] = i;
  			}
  		}
  	}
  
  	// A O(log n) function returning primefactorization
  	// by dividing by smallest prime factor at every step
  	static ArrayList<Integer> getFactorization(int x) {
  		ArrayList<Integer> ret = new ArrayList<>();
  		while (x != 1) {
  			ret.add(spf[x]);
  			x = x / spf[x];
  		}
  		return ret;
  	}
  
  	public static ArrayList<Integer> sieve(int n) {
  		int[] prime = new int[n + 1];
  		ArrayList<Integer> ans = new ArrayList<Integer>();
  		for (int p = 2; p <= n; p++) {
  			if (prime[p] == 0) {
  				ans.add(p);
  				for (int i = p * p; i <= n; i += p) {
  					prime[i] = 1;
  				}
  			}
  		}
  		return ans;
  	}
  
  	static class Reader {
  		final private int BUFFER_SIZE = 1 << 16;
  		private DataInputStream din;
  		private byte[] buffer;
  		private int bufferPointer, bytesRead;
  
  		public Reader() {
  			din = new DataInputStream(System.in);
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public Reader(String file_name) throws IOException {
  			din = new DataInputStream(new FileInputStream(file_name));
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public String next() throws IOException {
  			byte[] buf = new byte[100009];
  			int cnt = 0, c;
  			while ((c = read()) != -1) {
  				if (c <= ' ') {
  					if (cnt != 0) {
  						break;
  					} else {
  						continue;
  					}
  				}
  				buf[cnt++] = (byte) c;
  			}
  			return new String(buf, 0, cnt);
  		}
  
  		public int nextInt() throws IOException {
  			int ret = 0;
  			byte c = read();
  			while (c <= ' ') {
  				c = read();
  			}
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		public long nextLong() throws IOException {
  			long ret = 0;
  			byte c = read();
  			while (c <= ' ')
  				c = read();
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		public double nextDouble() throws IOException {
  			double ret = 0, div = 1;
  			byte c = read();
  			while (c <= ' ')
  				c = read();
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  
  			if (c == '.') {
  				while ((c = read()) >= '0' && c <= '9') {
  					ret += (c - '0') / (div *= 10);
  				}
  			}
  
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		private void fillBuffer() throws IOException {
  			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  			if (bytesRead == -1)
  				buffer[0] = -1;
  		}
  
  		private byte read() throws IOException {
  			if (bufferPointer == bytesRead)
  				fillBuffer();
  			return buffer[bufferPointer++];
  		}
  
  		public int[] readArray(int n) throws IOException {
  			int[] arr = new int[n];
  			for (int i = 0; i < n; i++) {
  				arr[i] = nextInt();
  			}
  			return arr;
  		}
  
  		public int[] readArray(int n, int x) throws IOException {
  			int[] arr = new int[n + x];
  			for (int i = x; i < n + x; i++) {
  				arr[i] = nextInt();
  			}
  			return arr;
  		}
  
  		public ArrayList<Integer> readList(int n) throws IOException {
  			ArrayList<Integer> a = new ArrayList<Integer>();
  			for (int i = 0; i < n; i++) {
  				a.add(nextInt());
  			}
  			return a;
  		}
  
  		public int[][] read2Array(int n, int m) throws IOException {
  			int[][] a = new int[n][m];
  			for (int i = 0; i < n; i++) {
  				for (int j = 0; j < m; j++) {
  					a[i][j] = nextInt();
  				}
  			}
  
  			return a;
  		}
  
  		public void close() throws IOException {
  			if (din == null)
  				return;
  			din.close();
  		}
  	}
  
  	public static int pow(int base, int index) {
  		if (index == 0) {
  			return 1;
  		} else if (index % 2 == 0) {
  			return pow(base * base, index / 2);
  		} else {
  			return base * pow(base * base, ((index - 1) / 2));
  		}
  	}
  
  	public static long pow(long base, long index) {
  		if (index == 0) {
  			return 1;
  		} else if (index % 2 == 0) {
  			return pow(base * base, index / 2);
  		} else {
  			return base * pow(base * base, ((index - 1) / 2));
  		}
  	}
  
  	static class pair {
  		long first;
  		long second;
  
  		pair() {
  			this.first = 0l;
  			this.second = 0l;
  		}
  
  		pair(long first, long second) {
  			this.first = first;
  			this.second = second;
  		}
  
  		void make_pair(long first, long second) {
  			this.first = first;
  			this.second = second;
  		}
  	}
  }