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

public class Main {
class Node {
    int id;
    int x;
    int y;
    public Node(int id,int x,int y){
        this.x=x;
        this.y=y;
        this.id=id;
    }

}
    void solve() {
        int n=ni();
         p=new Node[n];
         x=new int[n+1];
         y=new int[n+1];
        for(int i=0;i<n;i++){
            x[i+1]=ni(); y[i+1]=ni();
            p[i]=new Node(i+1,x[i+1],y[i+1]);
        }
        g=new ArrayList[n+1];
        for(int i=1;i<=n;i++) g[i]=new ArrayList<>();
        Arrays.sort(p, new Comparator<Node>() {
            @Override
            public int compare(Node t1, Node t2) {
                 int t=Integer.compare(t1.x,t2.x);
                 if(t!=0) return t;
                 t=Integer.compare(t1.y,t2.y);
                 return t;
            }
        });
        for(int i=1;i<n;i++){
            if(p[i].x==p[i-1].x){

                int id1=p[i].id,id2=p[i-1].id;

                g[id1].add(id2);
                g[id2].add(id1);

            }
        }
        Arrays.sort(p, new Comparator<Node>() {
            @Override
            public int compare(Node t1, Node t2) {
                int t=Integer.compare(t1.y,t2.y);
                if(t!=0) return t;
                t=Integer.compare(t1.x,t2.x);
                return t;
            }
        });
        for(int i=1;i<n;i++){
            if(p[i].y==p[i-1].y){
                int id1=p[i].id,id2=p[i-1].id;
                g[id1].add(id2);
                g[id2].add(id1);

            }
        }
        vis=new boolean[n+1];
        vis2=new boolean[n+1];
        long ans=1;
        for(int i=1;i<=n;i++){
            if(!vis2[i]){
                hsx.clear();
                hsy.clear();
                dfs2(i);
                long d=modpow(2,hsx.size()+hsy.size(),M);
                if(!dfs(i,-1)) d--;
                if(d<0) d+=M;
                ans=mul(ans,d,M);
               // pw.println(hsx.size()+" "+hsy.size());
//                for(int u : hsx) pw.print(u+" ");
//                pw.println("");
//                for(int u : hsy) pw.print(u+" ");
//                pw.println("");
            }
        }
        pw.println(ans);

    }
    Node p[];
    ArrayList<Integer> g[];
    boolean vis[];
    boolean vis2[];
    HashSet<Integer> hsx=new HashSet<>();
    HashSet<Integer> hsy=new HashSet<>();
    int x[];
    int y[];

    boolean dfs(int v,int pr){
        vis[v]=true;

        for(int u : g[v]){
            if(!vis[u]) {
              if(dfs(u,v))  return true;
            }
            else if(u!=pr) {
               // pw.println(u+" "+v+" "+pr);
                return true;
            }
        }
        return false;
    }
    void dfs2(int v){
        vis2[v]=true;
        hsx.add(x[v]);
        hsy.add(y[v]);

        for(int u : g[v]){
            if(!vis2[u]) dfs2(u);
        }
    }
    long mul(long x,long y,long M){
        x*=y;
        if(x>=M) x%=M;
        return x;
    }
    long modpow(long a, long b,long M)
    {
        long r=1;
        while(b>0)
        {
            if((b&1)>0) r=mul(r,a,M);
            a=mul(a,a,M);
            b>>=1;
        }
        return r;
    }
    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }

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

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}