#include <bits/stdc++.h>
const int mod = 1e9 + 7;
struct P {
  int x, y;
} p[100050];
int n;
long long fas(long long x, long long y) {
  long long ans = 1, bas = x;
  while (y) {
    if (y & 1) ans = ans * bas % mod;
    bas = bas * bas % mod;
    y >>= 1;
  }
  return ans;
}
namespace Graph {
int tot;
struct Ed {
  int nex, to;
} ed[400050];
int las[200050], cnt = 1;
void ad(int u, int v) { ed[++cnt].to = v, ed[cnt].nex = las[u], las[u] = cnt; }
bool vis[200050];
bool flag;
int siz;
void dfs(int u, int fr) {
  ++siz;
  vis[u] = 1;
  for (int i = las[u]; i; i = ed[i].nex) {
    int v = ed[i].to;
    if (i == (fr ^ 1)) continue;
    if (!vis[v])
      dfs(v, i);
    else
      flag = 1;
  }
}
}  // namespace Graph
using namespace Graph;
namespace Des {
struct X {
  int x, id;
} x[100050];
struct Y {
  int y, id;
} y[100050];
bool cmpx(const X& A, const X& B) { return A.x < B.x; }
bool cmpy(const Y& A, const Y& B) { return A.y < B.y; }
int px[100050], py[100050];
void Dinit() {
  std::sort(x + 1, x + 1 + n, cmpx);
  std::sort(y + 1, y + 1 + n, cmpy);
  x[0].x = y[0].y = 1 << 30;
  for (int i = 1; i <= n; ++i)
    px[x[i].id] = (x[i].x == x[i - 1].x ? tot : ++tot);
  for (int i = 1; i <= n; ++i)
    py[y[i].id] = (y[i].y == y[i - 1].y ? tot : ++tot);
}
}  // namespace Des
using namespace Des;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &p[i].x, &p[i].y);
    x[i] = (X){p[i].x, i}, y[i] = (Y){p[i].y, i};
  }
  Dinit();
  for (int i = 1; i <= n; ++i) ad(px[i], py[i]), ad(py[i], px[i]);
  long long ans = 1;
  for (int i = 1; i <= tot; ++i) {
    if (!vis[i]) {
      flag = 0;
      siz = 0;
      dfs(i, 0);
      if (flag)
        ans = ans * fas(2, siz) % mod;
      else
        ans = ((ans * (fas(2, siz) - 1)) % mod + mod) % mod;
    }
  }
  printf("%lld", ans);
  return 0;
}
