You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.

You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109 + 7.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of points.

n lines follow. The (i + 1)-th of these lines contains two integers xi, yi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the i-th point.

It is guaranteed that all points are distinct.

Output

Print the number of possible distinct pictures modulo 109 + 7.

Examples

Input

4
1 1
1 2
2 1
2 2


Output

16


Input

2
-1 -1
0 1


Output

9

Note

In the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it).

The first way: <image> The second way: <image>

In the second example you can work with two points independently. The number of pictures is 32 = 9.
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        HashSet<Integer> x = new HashSet<>(), y = new HashSet<>();
        HashMap<Integer, Integer> mapX = new HashMap<>(), mapY = new HashMap<>();
        int[][] arr = new int[2][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                arr[j][i] = sc.nextInt();
                if (j == 0) x.add(arr[j][i]);
                else y.add(arr[j][i]);
            }
        }

        int mapIdxX = 0;
        for (int xx : x) if (!mapX.containsKey(xx)) mapX.put(xx, mapIdxX++);
        for (int yy : y) if (!mapY.containsKey(yy)) mapY.put(yy, mapIdxX++);

        UnionFind uf = new UnionFind(mapIdxX);
        for (int i = 0; i < n; i++)
            uf.unionSet(mapX.get(arr[0][i]), mapY.get(arr[1][i]));

        uf.close();
        long res = 1;
        int mod = (int) 1e9 + 7;
        factorial();
        for (int i = 0; i < mapIdxX; i++)
            if (uf.p[i] == i) {
                int numPoints = uf.numPoints[i], lines = uf.sizeOfSet(i);
                long ways = 0;
                for (int j = 0; j <= Math.min(numPoints, lines); j++) {
                    ways += ncr(lines, j);
                    if (ways >= mod) ways -= mod;
                }
                res *= ways;
                res %= mod;

            }


        out.println(res);
        out.close();
    }

    // O(1) nCr
    static int MAX = 5 * 100000 + 1;
    static int fact[] = new int[MAX];
    static int MOD = (int) 1e9 + 7;

    static int ncr(int n, int r) {
        return (int) ((long) fact[n] * ((inv(fact[r], MOD) * inv(fact[n - r], MOD)) % MOD) % MOD) % MOD;
    }

    static long inv(long x, long mod) {
        long r, y;
        for (r = 1, y = mod - 2; y != 0; x = x * x % mod, y >>= 1)
            if ((y & 1) == 1)
                r = r * x % mod;
        return r;
    }

    static void factorial() {
        fact[0] = fact[1] = 1;
        for (int i = 2; i < MAX; i++)
            fact[i] = (int) ((long) i * fact[i - 1] % MOD);
    }

    public static long modular_exponentiation(long a, long b, long c) // returns ( a ^ b ) % c
    {
        long ans = 1L;
        while (b != 0) {
            if ((b & (1)) == 1)
                ans = (ans * a) % c;

            a = (a * a) % c;
            b >>= 1L;
        }

        return ans;
    }

    static class UnionFind {
        private int[] p, rank, setSize, numPoints;
        private int numSets;

        public UnionFind(int size) {
            p = new int[size];
            rank = new int[size];
            setSize = new int[size];
            numPoints = new int[size];
            numSets = size;
            for (int i = 0; i < size; ++i) {
                p[i] = i;
                numPoints[i] = 0;
                setSize[i] = 1;
            }
        }

        int findSet(int i) {
            return (p[i] == i) ? i : (p[i] = findSet(p[i]));
        }

        boolean isSameSet(int i, int j) {
            return findSet(i) == findSet(j);
        }

        void unionSet(int i, int j) {
            if (!isSameSet(i, j)) {
                --numSets;
                int x = findSet(i), y = findSet(j);
                if (rank[x] > rank[y]) {
                    p[y] = x;
                    setSize[x] = setSize[x] + setSize[y];
                    numPoints[x] = 1 + numPoints[x] + numPoints[y];
                } else {
                    p[x] = y;
                    setSize[y] = setSize[y] + setSize[x];
                    numPoints[y] = numPoints[y] + numPoints[x] + 1;
                    if (rank[x] == rank[y]) ++rank[y];
                }
            } else {
                numPoints[findSet(i)]++;
            }
        }

        int numDisjointSets() {
            return numSets;
        }

        void close() {
            for (int i = 0; i < p.length; i++)
                findSet(i);
        }

        int sizeOfSet(int i) {
            return setSize[findSet(i)];
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}