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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Contest {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Contest().run();
    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time(ms) = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class MyComparator implements Comparable<MyComparator> {

        int x;
        int y;

        public MyComparator(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(MyComparator a) {
            if (x == a.x) {
                return (y - a.y);
            }
            return x - a.x;
        }
    }

    public static boolean isPrime(int num) {
        if (num > 2 && num % 2 == 0) {
            //System.out.println(num + " is not prime");
            return false;
        }
        int top = (int) Math.sqrt(num) + 1;
        for (int i = 3; i < top; i += 2) {
            if (num % i == 0) {
                //System.out.println(num + " is not prime");
                return false;
            }
        }
        //System.out.println(num + " is prime");
        return true;
    }

    private static long gcd(long a, long b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.longValue();
    }

    public void solveD() throws IOException {

    }

    public void solve() throws IOException {
        int n = readInt();
        int[] x = new int[n];
        int[] y = new int[n];
        int[] z = new int[n];

        List<Point> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            x[i] = readInt();
            y[i] = readInt();
            z[i] = readInt();
            list.add(new Point(i, x[i], y[i], z[i]));
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (list.get(j).x > list.get(j + 1).x) {
                    Point swap = list.get(j);
                    list.set(j, list.get(j + 1));
                    list.set(j + 1, swap);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (list.get(j).x != list.get(j + 1).x) {
                    continue;
                }
                if (list.get(j).y > list.get(j + 1).y) {
                    Point swap = list.get(j);
                    list.set(j, list.get(j + 1));
                    list.set(j + 1, swap);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (list.get(j).x != list.get(j + 1).x) {
                    continue;
                }
                if (list.get(j).y != list.get(j + 1).y) {
                    continue;
                }
                if (list.get(j).z > list.get(j + 1).z) {
                    Point swap = list.get(j);
                    list.set(j, list.get(j + 1));
                    list.set(j + 1, swap);
                }
            }
        }

        /*for (Point p : list) {
            System.out.println(p);
        }*/

        for (int c = 1; c <= 3; c++) {
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    int count = 0;
                    Point p1 = list.get(i);
                    Point p2 = list.get(j);
                    if (p1.used || p2.used) {
                        continue;
                    }
                    if (p1.x != p2.x) {
                        count++;
                    }
                    if (p1.y != p2.y) {
                        count++;
                    }
                    if (p1.z != p2.z) {
                        count++;
                    }
                    if (count == c) {
                        System.out.println(p1.n + " " + p2.n);
                        p1.used = true;
                        p2.used = true;
                    }
                }
            }
        }
        
        
    }

    private class Point {

        final int n;

        final int x;
        final int y;
        final int z;

        boolean used = false;

        private Point(int n, int x, int y, int z) {
            this.n = n + 1;
            this.x = x;
            this.y = y;
            this.z = z;
        }

        private boolean pointInside(Point a, Point b) {
            if (this.x < Math.min(a.x, b.x)) {
                return false;
            }
            if (this.x > Math.max(a.x, b.x)) {
                return false;
            }
            if (this.y < Math.min(a.y, b.y)) {
                return false;
            }
            if (this.y > Math.max(a.y, b.y)) {
                return false;
            }
            if (this.z < Math.min(a.z, b.z)) {
                return false;
            }
            if (this.z > Math.max(a.z, b.z)) {
                return false;
            }
            return true;
        }

        public String toString() {
            return String.valueOf(x) + " " + String.valueOf(y) + " " + String.valueOf(z);
        }
    }

    public void solveB() throws IOException {
        int n = readInt();
        List<Integer> a = new LinkedList<>();
        List<Integer> b = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            a.add(readInt());
        }
        for (int i = 0; i < n; i++) {
            b.add(readInt());
        }
        Set<Integer> droppedCars = new HashSet<>();
        while (!a.isEmpty()) {
            if (droppedCars.contains(a.get(0))) {
                a.remove(0);
            } else if (a.get(0).intValue() != b.get(0).intValue()) {
                droppedCars.add(b.get(0));
                b.remove(0);
            } else {
                a.remove(0);
                b.remove(0);
            }
        }

        System.out.println(droppedCars.size());
    }

    public void solveA() throws IOException {
        int n = readInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = readInt();
        }
        boolean added = false;
        for (int i = 0; i < n; i++) {
            if (array[i] % 2 == 0) {
                System.out.println(array[i] / 2);
                continue;
            }
            if ((!added && array[i] > 0) || (added && array[i] < 0)) {
                System.out.println(array[i] / 2);
                added = !added;
            } else {
                System.out.println((array[i] / 2) + array[i] / Math.abs(array[i]));
                added = !added;
            }
        }
    }

    /**
     *
     * @param a
     * @param b
     * @return
     */
    private BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b.divide(a.gcd(b)));
    }

    public class LimitedQueue<E> extends LinkedList<E> {

        private int limit;

        public LimitedQueue(int limit) {
            this.limit = limit;
        }

        @Override
        public boolean add(E o) {
            super.addFirst(o);
            if (size() > limit) {
                super.removeLast();
            }
            return true;
        }
    }

}
