#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<int, int> kenx;
map<int, int> keny;
int st[100010][2], val[200010], fa[200010], num[200010], vis[200010],
    numedge[200010];
int findf(int x) { return fa[x] = fa[x] == x ? x : findf(fa[x]); }
long long pow(long long x, int k) {
  long long ans = 1;
  while (k) {
    if (k & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    k >>= 1;
  }
  return ans % mod;
}
int main() {
  int i, j;
  int n;
  while (cin >> n) {
    int cnt = 0;
    kenx.clear();
    keny.clear();
    for (i = 0; i < n; i++) {
      cin >> st[i][0] >> st[i][1];
      if (!kenx[st[i][0]]) {
        kenx[st[i][0]] = cnt;
        val[cnt++] = st[i][0];
      }
      if (!keny[st[i][1]]) {
        keny[st[i][1]] = cnt;
        val[cnt++] = st[i][1];
      }
    }
    for (i = 0; i < cnt; i++) fa[i] = i;
    memset(num, 0, sizeof(num));
    memset(vis, 0, sizeof(vis));
    for (i = 0; i < cnt; i++) numedge[i] = 1;
    for (i = 0; i < n; i++) {
      int fau = findf(kenx[st[i][0]]);
      int fav = findf(keny[st[i][1]]);
      if (fau != fav) {
        fa[fau] = fav;
        num[fav] += num[fau];
        numedge[fav] += numedge[fau];
      }
      num[fav] += 1;
    }
    long long ans = 1;
    for (i = 0; i < cnt; i++) {
      int fau = findf(i);
      if (!vis[fau]) {
        if (numedge[fau] > num[fau]) {
          ans = ((ans * ((pow((long long)2, numedge[fau]) - 1) % mod)) % mod +
                 mod) %
                mod;
        } else {
          ans = ((ans * (pow((long long)2, numedge[fau]) % mod)) % mod + mod) %
                mod;
        }
        vis[fau] = 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
