#include <bits/stdc++.h>
using namespace std;
int n;
pair<pair<int, int>, int> ps[666666], pp[666666];
int M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
  ++M;
  nxt[M] = fst[a];
  fst[a] = M;
  vb[M] = b;
}
void adde(int a, int b) {
  ad_de(a, b);
  ad_de(b, a);
}
map<int, int> bf;
bool vis[666666];
set<int> X, Y;
const int MOD = 1e9 + 7;
bool dfs(int x, int f = 0) {
  X.insert(pp[x].first.first);
  Y.insert(pp[x].first.second);
  bool g = 1;
  vis[x] = 1;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) {
      if (vis[b])
        g = 0;
      else
        g &= dfs(b, x);
    }
  return g;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &ps[i].first.first, &ps[i].first.second), ps[i].second = i,
                                                            pp[i] = ps[i];
  bf.clear();
  sort(ps + 1, ps + 1 + n);
  for (int i = 1; i <= n; ++i) {
    int& g = bf[ps[i].first.first];
    if (g) adde(ps[i].second, g);
    g = ps[i].second;
  }
  for (int i = 1; i <= n; ++i) swap(ps[i].first.first, ps[i].first.second);
  bf.clear();
  sort(ps + 1, ps + 1 + n);
  for (int i = 1; i <= n; ++i) {
    int& g = bf[ps[i].first.first];
    if (g) adde(ps[i].second, g);
    g = ps[i].second;
  }
  long long aa = 1;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    X.clear();
    Y.clear();
    int g = 0;
    if (dfs(i, 0)) g = 1;
    int rs = X.size() + Y.size();
    long long ans = 1;
    for (int i = 1; i <= rs; ++i) ans = ans * 2 % MOD;
    ans -= g;
    aa = aa * ans % MOD;
  }
  aa = (aa % MOD + MOD) % MOD;
  printf("%d\n", int(aa));
}
