#include <bits/stdc++.h>
using namespace std;
const int M = 222222;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
long long fac[M], inv[M], facinv[M], f[M];
void init() {
  f[0] = 1;
  for (int i = 1; i < M; ++i) f[i] = f[i - 1] * 2 % mod;
  fac[0] = fac[1] = inv[1] = facinv[0] = facinv[1] = 1;
  for (int i = 2; i < M; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    facinv[i] = facinv[i - 1] * inv[i] % mod;
  }
}
long long C(long long n, long long m) {
  if (n < 0 || m < 0 || m > n) return 0;
  return fac[n] * facinv[m] % mod * facinv[n - m] % mod;
}
const int N = 1e5 + 10;
map<int, int> mpx, mpy;
int cntx, cnty;
int x[N], y[N];
set<int> sx[N], sy[N], tmpx, tmpy, point;
queue<int> qx, qy;
bool visx[N], visy[N];
int main() {
  init();
  int n, tx, ty;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    if (!mpx.count(x[i])) mpx[x[i]] = ++cntx;
    if (!mpy.count(y[i])) mpy[y[i]] = ++cnty;
    tx = mpx[x[i]];
    ty = mpy[y[i]];
    sx[tx].insert(i);
    sy[ty].insert(i);
  }
  long long ans = 1;
  for (int i = 1; i <= n; ++i) {
    tx = mpx[x[i]];
    ty = mpy[y[i]];
    if (!visx[tx]) qx.push(tx);
    if (!visy[ty]) qy.push(ty);
    point.clear();
    visx[tx] = 1;
    visy[ty] = 1;
    int tmpx = 0, tmpy = 0;
    while (!qx.empty() || !qy.empty()) {
      while (!qx.empty()) {
        tmpx++;
        int t = qx.front();
        qx.pop();
        for (set<int>::iterator it = sx[t].begin(); it != sx[t].end(); ++it) {
          int id = *it;
          if (!visy[mpy[y[id]]]) {
            qy.push(mpy[y[id]]);
            visy[mpy[y[id]]] = 1;
          }
          point.insert(id);
        }
      }
      while (!qy.empty()) {
        tmpy++;
        int t = qy.front();
        qy.pop();
        for (set<int>::iterator it = sy[t].begin(); it != sy[t].end(); ++it) {
          int id = *it;
          if (!visx[mpx[x[id]]]) {
            qx.push(mpx[x[id]]);
            visx[mpx[x[id]]] = 1;
          }
          point.insert(id);
        }
      }
    }
    int l = tmpx + tmpy, p = point.size();
    if (!p) continue;
    long long tmp = f[l];
    if (l <= p)
      tmp = f[l];
    else
      tmp = f[l] - 1;
    ans = ans * tmp % mod;
  }
  printf("%I64d\n", ans);
}
