This is an easier version of the problem. In this version, n ≤ 2000.

There are n distinct points in three-dimensional space numbered from 1 to n. The i-th point has coordinates (x_i, y_i, z_i). The number of points n is even.

You'd like to remove all n points using a sequence of n/2 snaps. In one snap, you can remove any two points a and b that have not been removed yet and form a perfectly balanced pair. A pair of points a and b is perfectly balanced if no other point c (that has not been removed yet) lies within the axis-aligned minimum bounding box of points a and b.

Formally, point c lies within the axis-aligned minimum bounding box of points a and b if and only if min(x_a, x_b) ≤ x_c ≤ max(x_a, x_b), min(y_a, y_b) ≤ y_c ≤ max(y_a, y_b), and min(z_a, z_b) ≤ z_c ≤ max(z_a, z_b). Note that the bounding box might be degenerate. 

Find a way to remove all points in n/2 snaps.

Input

The first line contains a single integer n (2 ≤ n ≤ 2000; n is even), denoting the number of points.

Each of the next n lines contains three integers x_i, y_i, z_i (-10^8 ≤ x_i, y_i, z_i ≤ 10^8), denoting the coordinates of the i-th point.

No two points coincide.

Output

Output n/2 pairs of integers a_i, b_i (1 ≤ a_i, b_i ≤ n), denoting the indices of points removed on snap i. Every integer between 1 and n, inclusive, must appear in your output exactly once.

We can show that it is always possible to remove all points. If there are many solutions, output any of them.

Examples

Input


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


Output


3 6
5 1
2 4


Input


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


Output


4 5
1 6
2 7
3 8

Note

In the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on z = 0 plane). Note that order of removing matters: for example, points 5 and 1 don't form a perfectly balanced pair initially, but they do after point 3 is removed. 

<image>
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class CF {
	static class Point implements Comparable<Point>{
		public long x,y,z;
		public int idx;
		Point(){}
		Point(int id,long xx,long yy,long zz){
			idx=id;x=xx;y=yy;z=zz;
		}
		@Override
		public int compareTo(Point other) {
			if(x!=other.x) return (int) (x-other.x);
			else if(y!=other.y)return (int)(y-other.y);
			else return (int)(z-other.z);
		}
		@Override
		public String toString() {
			return Integer.toString(idx)+";"+Long.toString(x)+";"+Long.toString(y)+";"
			+Long.toString(z);
		}
	}
	static class KComparator implements Comparator<Point>{

		@Override
		public int compare(Point o1, Point o2) {
			if(o1.x!=o2.x)return (int)(o1.x-o2.x);
			else if(o1.y!=o2.y)return (int)(o1.y-o2.y);
			else return (int)(o1.z-o2.z);
		}
		
	}
	public static void main(String[] args) throws FileNotFoundException {
//		InputStream stream=new FileInputStream("in.txt");
		InputReader reader=new InputReader(System.in);
		int n=Integer.parseInt(reader.next());
		Point pArrayList[]=new Point[n];
		boolean vis[]=new boolean[n+10];
		for(int ii=0;ii<n;ii++) {
			pArrayList[ii]=new Point();
			pArrayList[ii].idx=ii+1;
			pArrayList[ii].x=Integer.parseInt(reader.next());
			pArrayList[ii].y=Integer.parseInt(reader.next());
			pArrayList[ii].z=Integer.parseInt(reader.next());
		}
		Arrays.sort(pArrayList,new KComparator());
		int l=0;
		for(int ii=1;ii<n;ii++) {
			if(l!=-1&&pArrayList[l].x==pArrayList[ii].x
					&&pArrayList[l].y==pArrayList[ii].y) {
				System.out.println(pArrayList[l].idx+" "+pArrayList[ii].idx);
				vis[l]=vis[ii]=true;
				l=-1;
			}
			else l=ii;
		}
		l=0;while(vis[l])l++;
		for(int ii=l+1;ii<n;ii++) {
			if(vis[ii])continue;
			if(l!=-1&&pArrayList[l].x==pArrayList[ii].x) {
					System.out.println(pArrayList[l].idx+" "+pArrayList[ii].idx);
					vis[l]=vis[ii]=true;
					l=-1;
			}
			else l=ii;
		}
		l=0;while(vis[l])l++;
		for(int ii=l+1;ii<n;ii++) {
			if(vis[ii])continue;
			if(l!=-1) {
				System.out.println(pArrayList[l].idx+" "+pArrayList[ii].idx);
				vis[l]=vis[ii]=true;
				l=-1;				
			}
			else l=ii;
		}
	}
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
    }
}
