#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int MAX = 400010;
constexpr int MOD = 1000000007;
struct DSU {
  int pre[MAX];
  void Clear() { memset(pre, -1, sizeof(pre)); }
  int Find(int x) { return pre[x] < 0 ? x : pre[x] = Find(pre[x]); }
  void Union(int a, int b) {
    int ra = Find(a), rb = Find(b);
    if (ra == rb) return;
    if (pre[ra] < pre[rb]) {
      pre[ra] += pre[rb];
      pre[rb] = ra;
    } else {
      pre[rb] += pre[ra];
      pre[ra] = rb;
    }
  }
  int Size(int x) { return -pre[Find(x)]; }
} dsu;
int p2[MAX], x[MAX], y[MAX], xx[MAX], yy[MAX], hx[MAX], hy[MAX];
unordered_set<int> cx[MAX], cy[MAX];
bool vis[MAX];
void Init(int n) {
  memset(hx, -1, sizeof(hx));
  memset(hy, -1, sizeof(hy));
  for (int i = 0; i < n; ++i) {
    cx[i].clear();
    cy[i].clear();
  }
  p2[0] = 1;
  for (int i = 1; i < MAX; ++i) {
    p2[i] = (p2[i - 1] << 1) % MOD;
  }
  dsu.Clear();
}
int Solve(int n) {
  int mx = 0, my = 0;
  for (int i = 0; i < n; ++i) {
    xx[mx++] = x[i];
    yy[my++] = y[i];
  }
  sort(xx, xx + mx);
  sort(yy, yy + my);
  mx = unique(xx, xx + mx) - xx;
  my = unique(yy, yy + my) - yy;
  for (int i = 0; i < n; ++i) {
    x[i] = lower_bound(xx, xx + mx, x[i]) - xx;
    y[i] = lower_bound(yy, yy + my, y[i]) - yy;
    if (hx[x[i]] == -1) {
      hx[x[i]] = i;
    } else {
      dsu.Union(i, hx[x[i]]);
    }
    if (hy[y[i]] == -1) {
      hy[y[i]] = i;
    } else {
      dsu.Union(i, hy[y[i]]);
    }
  }
  for (int i = 0; i < n; ++i) {
    int r = dsu.Find(i);
    cx[r].insert(x[i]);
    cy[r].insert(y[i]);
  }
  memset(vis, 0, sizeof(vis));
  i64 ret = 1;
  for (int i = 0; i < n; ++i) {
    int r = dsu.Find(i);
    if (vis[r]) continue;
    int l = (i64)(cx[r].size() + cy[r].size());
    int p = dsu.Size(r);
    i64 cur = p == (l - 1) ? (p2[l] - 1 + MOD) % MOD : p2[l];
    ret = (ret * cur) % MOD;
    vis[r] = true;
  }
  return (int)ret;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    Init(n);
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", &x[i], &y[i]);
    }
    int ans = Solve(n);
    printf("%d\n", ans);
  }
  return 0;
}
