#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
long long fa[500020], sz[500020], b[500020], vis[500020];
long long n, x[100020], y[100020];
map<long long, long long> mx, my;
inline long long getfather(long long x) {
  return fa[x] == x ? x : fa[x] = getfather(fa[x]);
}
long long hx = 0, hy = 100000;
inline long long ksm(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = (ans * x) % p, y--;
    x = (x * x) % p;
    y >>= 1;
  }
  return ans;
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= 200000; i++) fa[i] = i, sz[i] = 1;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    if (mx[x[i]] == 0) mx[x[i]] = ++hx;
    if (my[y[i]] == 0) my[y[i]] = ++hy;
    long long xx = mx[x[i]], yy = my[y[i]];
    long long fx = getfather(xx), fy = getfather(yy);
    if (fx != fy) {
      fa[fy] = fx;
      sz[fx] += sz[fy];
      b[fx] += b[fy] + 1;
    } else {
      b[fx]++;
    }
  }
  long long ans = 1;
  for (long long i = 1; i <= n; i++) {
    long long s = getfather(mx[x[i]]);
    if (!vis[s]) {
      if (sz[s] > b[s])
        ans = (ans * (ksm(2, sz[s]) - 1)) % p;
      else
        ans = (ans * ksm(2, sz[s])) % p;
      vis[s] = 1;
    }
    s = getfather(my[y[i]]);
    if (!vis[s]) {
      if (sz[s] > b[s])
        ans = (ans * (ksm(2, sz[s]) - 1)) % p;
      else
        ans = (ans * ksm(2, sz[s])) % p;
      vis[s] = 1;
    }
  }
  printf("%lld", ans);
  return 0;
}
