#include <bits/stdc++.h>
using namespace std;
const int64_t maxn = 3e5;
int64_t par[maxn], sz[maxn];
int64_t get(int64_t v) { return v == par[v] ? v : par[v] = get(par[v]); }
int64_t comp = 0;
int64_t ff[maxn], cyc[maxn];
void uni(int64_t a, int64_t b) {
  a = get(a);
  b = get(b);
  ff[a] = true;
  if (a == b) {
    cyc[a] = 1;
    return;
  }
  comp--;
  cyc[a] |= cyc[b];
  sz[a] += sz[b];
  par[b] = a;
}
int64_t gg(vector<int64_t> &X, int64_t x) {
  assert(binary_search(begin(X), end(X), x));
  return lower_bound(begin(X), end(X), x) - begin(X);
}
const int64_t mod = 1e9 + 7;
int64_t bpow(int64_t x, int64_t n) {
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 0) {
    return bpow(x * x % mod, n / 2);
  } else {
    return x * bpow(x, n - 1) % mod;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  iota(par, par + maxn, 0);
  fill(sz, sz + maxn, 1);
  int64_t n;
  cin >> n;
  int64_t x[n], y[n];
  map<int64_t, vector<int64_t>> xy, yx;
  set<int64_t> xx, yy;
  for (int64_t i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xx.insert(x[i]);
    yy.insert(y[i]);
  }
  vector<int64_t> X(begin(xx), end(xx));
  vector<int64_t> Y(begin(yy), end(yy));
  for (int64_t i = 0; i < n; i++) {
    uni(n + gg(X, x[i]), gg(Y, y[i]));
  }
  int64_t ans = 1;
  for (int64_t i = 0; i < maxn; i++) {
    if (i != par[i]) {
      continue;
    }
    if (ff[i]) {
      ans = ans * (bpow(2, sz[i]) - 1 + cyc[i] + mod) % mod;
    }
  }
  cout << ans << "\n";
  return 0;
}
