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.*; 
import java.math.*;
import java.util.*;
 
public class Main {
	static final int MOD = 998244353;
	//static final long MOD = 1000000007;
	static boolean[] visited;
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        int[][] points = new int[N][4];
        for (int i = 0; i < N; i++) {
        	points[i][0] = i;
        	for (int j = 1; j <= 3; j++)
        		points[i][j] = sc.nextInt();
        }
        boolean[] vis = new boolean[N];
        int[][] ans = new int[N/2][2];
        int index = 0;
        for (int i = 0; i < N-1; i++) {
        	if (vis[i]) continue;
        	int[] diff = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
        	int match = -1;
        	for (int j = i+1; j < N; j++) {
        		if (vis[j])continue;
        		int[] newDiff = new int[3];
        		for (int d = 0; d < 3; d++)
        			newDiff[d] = Math.abs(points[i][d+1]-points[j][d+1]);
        		if (newDiff[0] < diff[0] || (newDiff[0] == diff[0] && newDiff[1] < diff[1]) || (newDiff[0] == diff[0] && newDiff[1] == diff[1] && newDiff[2] < diff[2])) {
        			diff = newDiff;
        			match = j;
        		}
        	}
        	vis[i] = true;
        	vis[match] = true;
        	ans[index] = new int[]{i+1,match+1};
        	index++;
        }
        StringBuilder print = new StringBuilder();
        for (int i = 0; i < N/2; i++)
        	print.append(ans[i][0] + " " + ans[i][1] + "\n");
        System.out.print(print);
    }
    
    static class SegmentTreeRMQ { 
        int st[]; //array to store segment tree
        int n;
        
        public SegmentTreeRMQ(int n) {
        	this.n = n;
        }
      
        // A utility function to get minimum of two numbers 
        int minVal(int x, int y) { 
            return (x < y) ? x : y; 
        } 
      
        // A utility function to get the middle index from corner 
        // indexes. 
        int getMid(int s, int e) { 
            return s + (e - s) / 2; 
        } 
      
        /*  A recursive function to get the minimum value in a given 
            range of array indexes. The following are parameters for 
            this function. 
      
            st    --> Pointer to segment tree 
            index --> Index of current node in the segment tree. Initially 
                       0 is passed as root is always at index 0 
            ss & se  --> Starting and ending indexes of the segment 
                         represented by current node, i.e., st[index] 
            qs & qe  --> Starting and ending indexes of query range */
        int RMQUtil(int ss, int se, int qs, int qe, int index) 
        { 
            // If segment of this node is a part of given range, then 
            // return the min of the segment 
            if (qs <= ss && qe >= se) 
                return st[index]; 
      
            // If segment of this node is outside the given range 
            if (se < qs || ss > qe) 
                return Integer.MAX_VALUE; 
      
            // If a part of this segment overlaps with the given range 
            int mid = getMid(ss, se); 
            return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), 
                    RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); 
        } 
      
        // Return minimum of elements in range from index qs (quey 
        // start) to qe (query end).  It mainly uses RMQUtil() 
        int RMQ(int qs, int qe) 
        { 
            // Check for erroneous input values 
            if (qs < 0 || qe > n - 1 || qs > qe) { 
                System.out.println("Invalid Input");
                return -1; 
            } 
      
            return RMQUtil(0, n - 1, qs, qe, 0); 
        } 
      
        // A recursive function that constructs Segment Tree for 
        // array[ss..se]. si is index of current node in segment tree st 
        int constructSTUtil(int arr[], int ss, int se, int si) 
        { 
            // If there is one element in array, store it in current 
            //  node of segment tree and return 
            if (ss == se) { 
                st[si] = arr[ss]; 
                return arr[ss]; 
            } 
      
            // If there are more than one elements, then recur for left and 
            // right subtrees and store the minimum of two values in this node 
            int mid = getMid(ss, se); 
            st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), 
                    constructSTUtil(arr, mid + 1, se, si * 2 + 2)); 
            return st[si]; 
        } 
      
        /* Function to construct segment tree from given array. This function 
           allocates memory for segment tree and calls constructSTUtil() to 
           fill the allocated memory */
        void constructST(int arr[]) 
        { 
            // Allocate memory for segment tree 
      
            //Height of segment tree 
            int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
      
            //Maximum size of segment tree 
            int max_size = 2 * (int) Math.pow(2, x) - 1; 
            st = new int[max_size]; // allocate memory 
      
            // Fill the allocated memory st 
            constructSTUtil(arr, 0, n - 1, 0);
        }
    }
    
    public static long power(long x, long y, long p) { 
        // Initialize result
        long res = 1;
         
        // Update x if it is more   
        // than or equal to p 
        x = x % p;  
      
        while (y > 0) 
        { 
            // If y is odd, multiply x 
            // with result 
            if((y & 1)==1) 
                res = (res * x) % p; 
      
            // y must be even now 
            // y = y / 2 
            y = y >> 1;  
            x = (x * x) % p;  
        } 
        return res; 
    }
    
    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }
    
    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }
    
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  if (arr1[1] != arr2[1])
					  return arr1[1]-arr2[1];
				  else if (arr1[2] != arr2[2])
					  return arr1[2]-arr2[2];
				  else
					  return arr1[3]-arr2[3];
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        }
    }
}
class Node {
	public HashSet<Node> children;
	public int n;
	
	public Node(int n) {
		this.n = n;
		children = new HashSet<Node>();
	}
	
	public void addChild(Node node) {
		children.add(node);
	}
	
	public void removeChild(Node node) {
		children.remove(node);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return n;
	}

	@Override
	public boolean equals(Object obj) {
		if (! (obj instanceof Node)) {
			return false;
		} else {
			Node node = (Node) obj;
			return (n == node.n);
		}
	}
}