#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
unordered_map<long long, int> q;
int tot = 0;
vector<int> g[maxn];
bool vis[maxn], flag;
int d[maxn];
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int mul(int x, int y) {
  long long z = 1LL * x * y;
  return z - z / mod * mod;
}
int dfs(int u, int fa) {
  if (vis[u]) {
    flag = 1;
    return 0;
  }
  vis[u] = 1;
  int m = 1;
  for (auto v : g[u]) {
    if (v == fa) continue;
    m += dfs(v, u);
  }
  return m;
}
int powt(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}
int main() {
  int n, i, ans = 1;
  long long x, y;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    y += mod << 1;
    if (q[x] == 0) q[x] = ++tot;
    x = q[x];
    if (q[y] == 0) q[y] = ++tot;
    y = q[y];
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (i = 1; i <= tot; i++) {
    if (!vis[i]) {
      flag = 0;
      x = dfs(i, 0);
      if (flag)
        ans = mul(ans, powt(2, x));
      else
        ans = mul(ans, add(powt(2, x), mod - 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}
