#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200020, mod = 1e9 + 7;
int f[Maxn], c[Maxn], e[Maxn];
int x[Maxn], y[Maxn];
int pw[Maxn];
int find(int u) { return f[u] == u ? u : (f[u] = find(f[u])); }
void merge(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) {
    e[u]++;
  } else {
    f[u] = v;
    e[v] += e[u] + 1;
    c[v] += c[u];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> vx, vy;
  for (int i = 0; i < n; i++)
    scanf("%d%d", x + i, y + i), vx.push_back(x[i]), vy.push_back(y[i]);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  for (int i = 0; i < n; i++)
    x[i] = lower_bound(vx.begin(), vx.end(), x[i]) - vx.begin();
  for (int i = 0; i < n; i++)
    y[i] = lower_bound(vy.begin(), vy.end(), y[i]) - vy.begin();
  for (int i = 0; i < Maxn; i++) f[i] = i, c[i] = 1, e[i] = 0;
  for (int i = 0; i < n; i++) {
    int u, v;
    u = x[i], v = y[i];
    merge(u, v + Maxn / 2);
  }
  pw[0] = 1;
  for (int i = 1; i < Maxn; i++) pw[i] = pw[i - 1] * 2 % mod;
  int ans = 1;
  for (int i = 0; i < Maxn; i++) {
    if (f[i] == i) {
      if (c[i] <= e[i]) {
        ans = 1LL * ans * pw[c[i]] % mod;
      } else {
        if (e[i]) {
          ans = 1LL * ans * (pw[c[i]] - 1) % mod;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
