Problem: The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.

Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge contains its value written on it as a non-negative integer.

A bad boy Vasya came up to the board and wrote number sv near each node v — the sum of values of all edges that are incident to this node. Then Vasya removed the edges and their values from the board.

Your task is to restore the original tree by the node colors and numbers sv.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 105) — the number of nodes in the tree. Next n lines contain pairs of space-separated integers ci, si (0 ≤ ci ≤ 1, 0 ≤ si ≤ 109), where ci stands for the color of the i-th vertex (0 is for white, 1 is for black), and si represents the sum of values of the edges that are incident to the i-th vertex of the tree that is painted on the board.

Output

Print the description of n - 1 edges of the tree graph. Each description is a group of three integers vi, ui, wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 0 ≤ wi ≤ 109), where vi and ui — are the numbers of the nodes that are connected by the i-th edge, and wi is its value. Note that the following condition must fulfill cvi ≠ cui.

It is guaranteed that for any input data there exists at least one graph that meets these data. If there are multiple solutions, print any of them. You are allowed to print the edges in any order. As you print the numbers, separate them with spaces.

Examples

Input

3
1 3
1 2
0 5


Output

3 1 3
3 2 2


Input

6
1 0
0 3
1 8
0 2
0 3
0 0


Output

2 3 3
5 3 3
4 3 2
1 6 0
2 1 0

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
 
public class Main {
      
    int mod = 1000000007;

    public void solve() throws IOException{
    
      int n = in.nextInt();

      PriorityQueue<Pair<Integer, Integer>> pq1 = new PriorityQueue<>((e1, e2) -> (e1.x - e2.x));
      PriorityQueue<Pair<Integer, Integer>> pq2 = new PriorityQueue<>((e1, e2) -> (e1.x - e2.x));

      for(int i = 1; i <= n; i++){
         int c = in.nextInt();
         int s = in.nextInt();
         if(c == 0){
            pq1.add(new Pair<Integer, Integer>(s, i));
         }else{
            pq2.add(new Pair<Integer, Integer>(s, i));
         }
      }

      while(!pq1.isEmpty() || !pq2.isEmpty()){
         int v1 = pq1.peek().x;
         int n1 = pq1.peek().y;
         int v2 = pq2.peek().x;
         int n2 = pq2.peek().y;
         pq1.poll(); pq2.poll();
         if(v1 >= v2){
            pq1.add(new Pair<Integer, Integer>(v1 - v2, n1));
         }else if(v1 < v2){
            pq2.add(new Pair<Integer, Integer>(v2 - v1, n2));
         }
         
         out.println(n1 + " " + n2 + " " + Math.min(v1, v2));
         
         if(pq1.isEmpty()){
            while(!pq2.isEmpty()){
               Pair<Integer, Integer> p = pq2.poll();
               if(p.y == n2) continue;
               out.println(n1 + " " + p.y + " " + 0);
            }
         }

         if(pq2.isEmpty()){
            while(!pq1.isEmpty()){
               Pair<Integer, Integer> p = pq1.poll();
               if(p.y == n1) continue;
               out.println(n2 + " " + p.y + " " + 0);
            }
         }
      }


      return;
    }
    
    public long exp(int b, int e){
       if(e == 0){
          return 1;
       }else if(e % 2 == 1){
          long r = exp(b, e / 2);
          return r * r % mod * b % mod;
       }else if(e % 2 == 0){
          long r = exp(b, e / 2);
          return r * r % mod;
       }
       return 1;
    }

       FastScanner in;
       PrintWriter out;
    
    static class FastScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }
 
        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        String nextLine() throws IOException {
            if (st == null || !st.hasMoreTokens())
                return br.readLine();
            StringBuilder result = new StringBuilder(st.nextToken());
            while (st.hasMoreTokens()) {
                result.append(" ");
                result.append(st.nextToken());
            }
            return result.toString();
        }
 
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
 
    }
 
    void run() throws IOException {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }
 
    public static void main(String[] args) throws IOException{
        new Main().run();
    }
 
    public void printArr(int[] arr){
        for(int i = 0; i < arr.length; i++){
            out.print(arr[i] + " ");
        }
        out.println();
    }
 
    public long gcd(long a, long b){
        if(a == 0) return b;
        return gcd(b % a, a);
    }

    public boolean isPrime(long num){

        if(num == 0 || num == 1){
            return false;
        }

        for(int i = 2; i * i <= num; i++){
            if(num % i == 0){
                return false;
            }
        }

        return true;
    }

    public class Pair<A, B>{
        public A x; 
        public B y;

        Pair(A x, B y){
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!x.equals(pair.x)) return false;
            return y.equals(pair.y);
        }

        @Override
        public int hashCode() {
            int result = x.hashCode();
            result = 31 * result + y.hashCode();
            return result;
        }

    }

    class Tuple{
        int x; int y; int z;
        Tuple(int ix, int iy, int iz){
            x = ix;
            y = iy;
            z = iz;
        }
    }
}