On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and b is said to be the following value: <image> (the distance calculated by such formula is called Manhattan distance).

We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value <image>.

Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length.

Input

The first line contains integer n (1 ≤ n ≤ 106).

The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106).

It is guaranteed that no two points coincide.

Output

Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality <image>.

If there are multiple possible answers, print any of them.

It is guaranteed that the answer exists.

Examples

Input

5
0 7
8 10
3 4
5 0
9 12


Output

4 3 1 2 5 

Note

In the sample test the total distance is:

<image>

(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26
import java.io.IOException;
import java.util.*;

public class MyClass {

    private static class Point {
        Integer index;
        Integer group;
        Integer x;
        Integer y;
    };

    public static void main(String[] args) {
        List<List<Point>> groups = new ArrayList<>();
        for (int i = 0; i <= 1000; i++) {
            groups.add(new ArrayList<>());
        }

        FasterScanner sc = new FasterScanner();
        StringBuilder ans = new StringBuilder();

        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            Point p = new Point();
            p.index = i + 1;

            p.x = sc.nextInt();
            p.y = sc.nextInt();
            p.group = p.x / 1000;
            groups.get(p.group).add(p);
        }

        Comparator<Point> comp = (p1, p2) -> {
            if (p1.group % 2 == 0) {
                return (p1.y).compareTo(p2.y);
            } else {
                return -(p1.y).compareTo(p2.y);
            }
        };

        groups.forEach(group -> {
            group.stream()
                .sorted(comp)
                .forEach(point -> ans.append(point.index + " "));
        });

        System.out.println(ans);
    }

     public static class FasterScanner {
         private byte[] buf = new byte[1024];
         private int curChar;
         private int numChars;

         public int read() {
             if (numChars == -1)
                 throw new InputMismatchException();
             if (curChar >= numChars) {
                 curChar = 0;
                 try {
                     numChars = System.in.read(buf);
                 } catch (IOException e) {
                     throw new InputMismatchException();
                 }
                 if (numChars <= 0)
                     return -1;
             }
             return buf[curChar++];
         }

         public int nextInt() {
             int c = read();
             while (isSpaceChar(c))
                 c = read();
             int sgn = 1;
             if (c == '-') {
                 sgn = -1;
                 c = read();
             }
             int res = 0;
             do {
                 if (c < '0' || c > '9')
                     throw new InputMismatchException();
                 res *= 10;
                 res += c - '0';
                 c = read();
             } while (!isSpaceChar(c));
             return res * sgn;
         }

         private boolean isSpaceChar(int c) {
             return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
         }
     }
}
