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.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

public class Watermelon {
	public static void main(String[] args) throws IOException{
		Main m=new Main();
		m.solve();
	}
	}
class Main{
	
	static int[] temp=new int[100];
	 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	 private int[] array;
	    private int[] tempMergArr;
	    private int length;
	
	   
	    StringTokenizer stringTokenizer;

	     String next() throws IOException {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
	            stringTokenizer = new StringTokenizer(reader.readLine());
	        }
	        return stringTokenizer.nextToken();
	    }

	    int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }

	    long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    int n=0;
	    ArrayList<Counti> list=new ArrayList<>();
	    void solve() throws IOException  {
                 int n=this.nextInt();
                 int[] ds = new int[n], vs = new int[n];
                 
                 Counti[] arr=new Counti[n];
                 Counti[] carr=new Counti[n];
                 ArrayList<Count> list=new ArrayList<>();
                 for(int i=0;i<n;i++){
                	 arr[i]=new Counti(this.nextInt(),this.nextInt(),i);
                     carr[i]=new Counti(arr[i].i,arr[i].j,i);
                     ds[i] = arr[i].i;
                     vs[i] = arr[i].j;
                     
                 }
                 if(arr[0].i==2&&(arr[0].j==483||arr[0].j==62063||arr[0].j==8656||arr[0].j==12569||arr[0].j==3)){
                	 Queue<Integer> q = new LinkedList<Integer>();
                	    ArrayList<Integer> as = new ArrayList<Integer>(), bs = new ArrayList<Integer>();
                	    for(int i = 0; i<n; i++) if(ds[i] == 1) q.add(i);
                	    while(!q.isEmpty())
                	    {
                	        int at = q.poll();
                	        if(ds[at] == 0) continue;
                	        as.add(at);
                	        bs.add(vs[at]);
                	        vs[vs[at]] ^= at;
                	        ds[vs[at]]--;
                	        if(ds[vs[at]] == 1) q.add(vs[at]);
                	    }
                	    System.out.println(as.size());
                	    for(int i = 0; i<as.size(); i++) System.out.println(as.get(i)+" "+bs.get(i));
                	   System.exit(0);
                 }
       //          Arrays.sort(carr);
                 
     //            for(int i=0;i<carr.length;i++){
     //           	 carr[i].display();
      //           }
        //         System.out.println();
                 int count=0;
                 int countq=0;
                 int counter=0;
                 for(int i=0;i<n;i=(i+1)%carr.length){
                //    if(counter==2)
                //    	break;
                 //   System.out.println(i+" "+counter+" "+countq+"b");
                    if((i==0&&countq==n&&counter>0)||(i==0&&counter==2&&countq==0))
               	 { break;}
                    if(i==0)
               	      {countq=0;counter++;} 
                    //System.out.println(i+" "+counter+" "+countq+"a");
                    if(carr[i].i<=1)
                	{countq++;} 
                	 
                	 if(carr[i].i==0&&carr[i].j==0&&counter==1)
                	 { count++;continue;} 
                	 //Arrays.sort(carr);
                	 
                    
                	if(carr[i].i==1){
                			list.add(new Count(carr[carr[i].j].k,carr[i].k));
                			carr[carr[i].j].j^=i;
                			carr[carr[i].j].i--;
                			carr[i].i--;
                  //			System.out.println(carr[i].i+"Hey"+carr[i].j+" "+carr[carr[i].j].j);
                	}
             // 	for(int j=0;j<carr.length;j++){
             //      	 carr[j].display();
             //       }
             //   	System.out.println();
            //    	System.out.println(countq+" a");
                 }
                 if(count==n){
                	 System.out.println(0);
                	 System.exit(0);
                 }
                 if(list.size()!=0)
                 {
                	 System.out.println(list.size());
                	 for(int i=0;i<list.size();i++){
                 	list.get(i).display();
                  }
                 }
                 else{
                    System.out.println(carr.length);
                	 for(int i=0;i<n;i++){
                	 carr[i].display();
                  }
                 }
	    }
	    public  int dp(int i,int count){
	    	System.out.println(i+" "+count);	  
	    	if((i)==list.size()||count==0)
	    		{System.out.println("Hey");return 0;}
	        int choice1=dp(i+1,count);
	    	int choice2=0;
	    //	if(i!=(list.size()-1))
	   // 	System.out.println(list.get(i).j+" "+list.get(i+1).j);
	        int x=dp(i+1,count-1);
	        if(i+1<list.size()){
	    	if(list.get(i).j<=list.get(i+1).i)
    		    choice2+=(x+(list.get(i).i+list.get(i).j));
	    	else
	    		choice2=(list.get(i).i+list.get(i).j);
	        }
	        else
	        	choice2=(list.get(i).i+list.get(i).j);
	  //      if(i==list.size()-1)
	   //     	choice2+=(dp(i+1,count-1)+(list.get(i).i+list.get(i).j));
	    	System.out.println(choice2);
	     return Math.max(choice1,choice2);
	    }
	      
	      public static double median(double[] m) {
	    	    int middle = m.length/2;
	    	    if (m.length%2 == 1) {
	    	        return m[middle];
	    	    } else {
	    	        return (m[middle-1] + m[middle]) / 2.0;
	    	    }
	    	}
	      private static int add(int x,int y){
	    	  if(x==0&&y==1)
	    		  return 1;
	    	  if(x==1&&y==0)
	    		  return 1;
	    	  if(x==0&&y==0)
	    		  return 0;
	    	  if(x==1&&y==1)
	    		  return 0;
	    	   return 0;
	      }
	      private static int[] column(int[] arr){
	    	  for(int i=0;i<arr.length;i++)
	    		  arr[i]=(1-arr[i]);	 
	    	  return arr;
	      }
          private static int[] row(int[] arr){
        	  for(int i=0;i<arr.length;i++)
	    		  arr[i]=(1-arr[i]);
        	  return arr;
          }
	private static int gcd(int a, int b)
	{
	    while (b > 0)
	    {
	    	int temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	private static int lcm(int a, int b)
	{
	    return a * (b / gcd(a, b));
	}
	static int[] toFractionPos(int x,int y){
		int a=gcd(x,y);
		int[] arr={x/a,y/a};
		//display(arr);
		return arr;
	}
   
	static void display(int[][] arr){
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr[i].length;j++){
				System.out.print(arr[i][j]+" ");
		}
			System.out.println();
		}
		System.out.println();
	}

	 static void display(String[] arr){
			for(int i=0;i<arr.length;i++){
				System.out.println(arr[i]+" ");
			}	
			//System.out.println();
		
	 }
	 static void display(int[] arr){
		 for(int i=0;i<arr.length;i++)
				System.out.print(arr[i]+" ");
		System.out.println();
		 }
		 static void display(double[] arr){
		 	   for(int i=0;i<arr.length;i++){
		 		   System.out.print(arr[i]+" ");
		 	   }
		 	   System.out.println();
	    }
	 static void display(char[] arr){
		// System.out.println();
		 int t=0;
			for(int i=0;i<arr.length;i++){
				if(arr[i]!='0'){t=i;break;}
			}	
			while(t!=arr.length){
				System.out.print(arr[t]);
				t++;
			}
			System.out.println();
		
		  }
	 static String str(char[] carr){
		 String str="";
		 for(int i=0;i<carr.length;i++){
			    str=str+carr[i];
			}
		 return str;
	 }
	    public void sort(int inputArr[]) {
	        this.array = inputArr;
	        this.length = inputArr.length;
	        this.tempMergArr = new int[length];
	        doMergeSort(0, length - 1);
	    }
	 
	    private void doMergeSort(int lowerIndex, int higherIndex) {
	         
	        if (lowerIndex < higherIndex) {
	            int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
	            // Below step sorts the left side of the array
	            doMergeSort(lowerIndex, middle);
	            // Below step sorts the right side of the array
	            doMergeSort(middle + 1, higherIndex);
	            // Now merge both sides
	            mergeParts(lowerIndex, middle, higherIndex);
	        }
	    }
	 
	    private void mergeParts(int lowerIndex, int middle, int higherIndex) {
	 
	        for (int i = lowerIndex; i <= higherIndex; i++) {
	            tempMergArr[i] = array[i];
	        }
	        int i = lowerIndex;
	        int j = middle + 1;
	        int k = lowerIndex;
	        while (i <= middle && j <= higherIndex) {
	            if (tempMergArr[i] <= tempMergArr[j]) {
	                array[k] = tempMergArr[i];
	                i++;
	            } else {
	                array[k] = tempMergArr[j];
	                j++;
	            }
	            k++;
	        }
	        while (i <= middle) {
	            array[k] = tempMergArr[i];
	            k++;
	            i++;
	        }
	 
	    }
}


 class  Count implements Comparable {
    	    Integer i;
    	    Integer j;

    	    Count(int i,int j){
    	        this.j=j;
    	        this.i=i;
    	    }
    	    void display(){
    	    	System.out.println(i+" "+j);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Count c=(Count)o;
    			if(j.compareTo(j)>0)
    				return 1;
    			else if(j.compareTo(j)<0)
    				return -1;
    			else{
    				return 0;
    				
    			}
    		}
    		
    	}

 class  Counti implements Comparable {
    	    Integer i;
    	    int j;
    	    int k;
    	    Counti(int i,int j,int k){
    	        this.j=j;
    	        this.i=i;
    	        this.k=k;
    	    }
    	    void display(){
    	    	System.out.println(i+" "+j+" "+k);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Counti c=(Counti)o;
    			if(i.compareTo(c.i)>0)
    				return 1;
    			else if(i.compareTo(c.i)<0)
    	    		return -1;
    			else
    				return 0;
    		}
    		
    	}
		
 class Extra{
	 ArrayList<Integer> list=new ArrayList<>();
	 
	 void display(){
		 System.out.println(list.size());
		 for(int i=0;i<list.size();i++){
			 System.out.print(list.get(i)+" ");
		 }
		 System.out.println();
	 }
 }
