#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
struct dian {
  int x, y, id;
} a[N];
int Pow(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    k >>= 1;
  }
  return res;
}
int cir[N], f[N];
int get(int x) {
  if (x != f[x]) f[x] = get(f[x]);
  return f[x];
}
long long ans = 1;
int n, b[N], siz[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++) f[i] = i, siz[i] = 1;
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  for (int i = 1; i <= n; i++) b[i] = a[i].x;
  sort(b + 1, b + n + 1);
  int len = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++)
    a[i].x = lower_bound(b + 1, b + len + 1, a[i].x) - b;
  for (int i = 1; i <= n; i++) b[i] = a[i].y;
  sort(b + 1, b + n + 1);
  len = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++)
    a[i].y = lower_bound(b + 1, b + len + 1, a[i].y) - b;
  for (int i = 1; i <= n; i++) {
    int x = get(a[i].x), y = get(a[i].y + n);
    if (x ^ y) {
      f[y] = x;
      siz[x] += siz[y];
      cir[x] |= cir[y];
    } else
      cir[x] = 1;
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (f[i] == i) {
      long long res = Pow(2, siz[i]);
      if (!cir[i]) res = ((res - 1) % mod + mod) % mod;
      ans = ans * res % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
