#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int fa[200005];
int n, sz1, sz2;
int x[200005], y[200005];
int xx[200005], yy[200005];
int cntb[200005], cntd[200005];
int find(int now) { return fa[now] == now ? now : fa[now] = find(fa[now]); }
long long quickpow(long long p, long long k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = (ans * p) % mod;
    p = (p * p) % mod;
    k >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    xx[i] = x[i];
    yy[i] = y[i];
  }
  sort(xx + 1, xx + 1 + n);
  sz1 = (unique(xx + 1, xx + 1 + n) - (xx + 1));
  sort(yy + 1, yy + 1 + n);
  sz2 = (unique(yy + 1, yy + 1 + n) - (yy + 1));
  for (int i = 1; i <= sz1 + sz2; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    x[i] = lower_bound(xx + 1, xx + 1 + sz1, x[i]) - xx;
    y[i] = (lower_bound(yy + 1, yy + 1 + sz2, y[i]) - yy) + sz1;
    fa[find(x[i])] = find(y[i]);
  }
  for (int i = 1; i <= n; i++) cntd[find(x[i])]++;
  for (int i = 1; i <= sz1 + sz2; i++) cntb[find(i)]++;
  long long ans = 1;
  for (int i = 1; i <= sz1 + sz2; i++) {
    if (find(i) == i) {
      if (cntd[i] + 1 == cntb[i]) {
        ans *= (quickpow(2, cntb[i]) - 1);
        ans %= mod;
      } else {
        ans *= (quickpow(2, cntb[i]));
        ans %= mod;
      }
    }
  }
  printf("%I64d\n", ans);
}
