Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0). 

Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

Input

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.

The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

Output

In the first line print number m, the number of edges of the graph.

Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).

Edges can be printed in any order; vertices of the edge can also be printed in any order.

Examples

Input

3
2 3
1 0
1 0


Output

2
1 0
2 0


Input

2
1 1
1 0


Output

1
0 1

Note

The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.concurrent.LinkedBlockingDeque;

import javax.swing.border.Border;

public class a {

	public static long mod = (long) Math.pow(10, 9) + 7;
	public static int k = 0;

	private static class node {
		int x;
		int y;
		int dis;

		node(int m, int n, int g) {
			x = m;
			y = n;
			dis = g;
		}

	}

	public static class point implements Comparable<point> {
		int x;
		int y;
		int dis;

		point(int x, int y, int b) {
			this.x = x;
			this.y = y;
			this.dis = b;
		}

		@Override
		public int compareTo(point o) {
			if (o.dis < dis)
				return 1;
			return -1;

		}
	}

	public static int ch(long y) {
		int r = Long.bitCount(y);
		return r;
	}

	public static long gcd(long x, long y) {
		if (y == 0)
			return x;

		return gcd(y, x % y);
	}

	public static boolean ch[];
	public static ArrayList<Integer> prime;
	public static Queue<Integer> pp;

	public static void sieve(int k) {
		ch[0] = ch[1] = true;

		for (int i = 2; i <= k; i++) {
			if (!ch[i]) {
				prime.add(i);
				pp.add(i);
				for (int j = i + i; j <= k; j += i) {
					ch[j] = true;
				}
			}
		}

	}

	public static long pw(int x, int power, int mod) {
		if (power == 1)
			return x % mod;
		else if (power % 2 == 0)
			return pw((x % mod * x % mod) % mod, power / 2, mod);
		else
			return (pw(x, power - 1, mod) % mod * x % mod) % mod;

	}

	public static int swap[][];
	public static int parent[];

	public static boolean graph(int s, int e, int n) {
		boolean ch[] = new boolean[400];
		Arrays.fill(parent, -1);
		Queue<Integer> q = new LinkedList<>();
		ch[s] = true;
		if (s == e)
			return true;
		q.add(s);
		while (!q.isEmpty()) {
			int r = q.poll();

			if (r == e)
				return true;

			for (int i = 0; i < n; i++) {
				if (!ch[i] && swap[r][i] == 1) {
					q.add(i);
					parent[i] = r;
					ch[i] = true;

				}
			}
		}

		return false;

	}

	public static char a[][];
	public static ArrayList<Integer> b[][];
	public static int n;
	public static int m;
	public static int ans[][];
	public static int dx[] = { 1, 0, -1, 0 };
	public static int dy[] = { 0, 1, 0, -1 };
	public static boolean ok[][];

	public static boolean ch1(int x, int y, int dis) {

		for (int i = 0; i < b[x][y].size(); i++) {
			if (dis % 4 == b[x][y].get(i))
				return false;
		}
		return true;
	}

	public static boolean ch2(int x, int y, int dis) {
		for (int i = 0; i < 4; i++) {
			int x1 = x + dx[i];
			int y1 = y + dy[i];
			if (x1 < 0 || y1 < 0 || x1 >= n || y1 >= m)
				continue;
			if (a[x1][y1] != '.' && a[x1][y1] != 'G' && a[x1][y1] != 'S')
				continue;
			if (ch1(x1, y1, dis))
				return true;
		}
		return false;
	}

	public static int dig(int x, int y) {
		ok = new boolean[n][m];
		ans = new int[n][m];

		PriorityQueue<point> q = new PriorityQueue<>();
		q.add(new point(x, y, 0));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ans[i][j] = Integer.MAX_VALUE;
			}
		}
		ans[x][y] = 0;
		while (!q.isEmpty()) {
			point r = q.poll();
			int x1 = r.x;
			int y1 = r.y;
			// System.out.println(x1+" "+y1);
			int dis = r.dis;
			if (a[x1][y1] == 'G')
				return dis;
			boolean ee = ch2(x1, y1, dis + 1);
			for (int i = 0; i < 4; i++) {
				int x2 = dx[i] + x1;
				int y2 = dy[i] + y1;
				if (x2 < 0 || y2 < 0 || x2 >= n || y2 >= m)
					continue;
				if (a[x2][y2] != '.' && a[x2][y2] != 'G' && a[x2][y2] != 'S')
					continue;
				if (ans[x2][y2] > dis + 1 && ch1(x2, y2, dis + 1)) {
					ans[x2][y2] = dis + 1;
					q.add(new point(x2, y2, dis + 1));
				} else {

					if (ans[x2][y2] > dis + 3 && ee && ch1(x1, y1, dis + 2)
							&& ch1(x2, y2, dis + 3)) {

						ans[x2][y2] = dis + 3;
						q.add(new point(x2, y2, dis + 3));
					}
				}

			}

		}

		return -1;
	}

	public static void up(int x, int y, int num) {
		for (int i = x - 1; i >= 0; i--) {
			if (w[i][y] == 0)
				break;
			b[i][y].add(num);

		}

	}

	public static void down(int x, int y, int num) {
		for (int i = x + 1; i < n; i++) {
			if (w[i][y] == 0)
				break;
			b[i][y].add(num);

		}

	}

	public static void left(int x, int y, int num) {
		for (int i = y + 1; i < m; i++) {
			if (w[x][i] == 0)
				break;
			b[x][i].add(num);

		}

	}

	public static void right(int x, int y, int num) {
		for (int i = y - 1; i >= 0; i--) {
			if (w[x][i] == 0)
				break;
			b[x][i].add(num);

		}

	}

	public static int w[][];

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		// PrintWriter out = new PrintWriter(new FileWriter("out.txt"));
		int n = Integer.parseInt(in.readLine());
		ArrayList<Integer> graph[] = new ArrayList[n];
		int deg[] = new int[n];
		int s[] = new int[n];

		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList();
			String y[] = in.readLine().split(" ");
			deg[i] = Integer.parseInt(y[0]);
			s[i] = Integer.parseInt(y[1]);
		}
		int xor[] = new int[n];
		for (int i = 0; i < n; i++) {
			int k = i;
			while (deg[k] - 1 == graph[k].size()) {
				int one = xor[k];
				int two = s[k];
				int ans = one ^ two;
				graph[k].add(ans);
				graph[ans].add(k);
				xor[ans] ^= k;
				k = ans;
			}
		}
		HashSet<String> mp = new HashSet();
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < graph[i].size(); j++) {
				String st = Math.min(i, graph[i].get(j)) + " "
						+ Math.max(i, graph[i].get(j));
				if (!mp.contains(st)) {
					mp.add(st);
					qq.append(i + " " + graph[i].get(j) + "\n");
					c++;
				}
			}
		}
		System.out.println(c);

		System.out.println(qq);
		out.close();

	}
}