#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, mod = 1e9 + 7;
map<pair<long long, long long>, vector<pair<long long, long long> > > adj;
map<long long, vector<long long> > X, Y;
map<pair<long long, long long>, bool> B;
vector<pair<long long, long long> > nodes;
long long f, n, a, b, ans = 1LL, tv[N];
set<long long> XX, YY;
void add(long long x, long long y, long long x2, long long y2) {
  adj[make_pair(x, y)].push_back(make_pair(x2, y2)),
      adj[make_pair(x2, y2)].push_back({x, y});
}
void DFS(pair<long long, long long> u,
         pair<long long, long long> p = make_pair(-1, -1)) {
  XX.insert(u.first), YY.insert(u.second);
  B[u] = 1;
  for (auto x : adj[u]) {
    if (x == p) continue;
    if (B[x]) {
      f = 0;
      continue;
    }
    DFS(x, u);
  }
}
int32_t main() {
  scanf("%I64d", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d %I64d", &a, &b);
    X[a].push_back(b), Y[b].push_back(a);
    nodes.push_back({a, b});
  }
  for (auto &x : X) {
    sort(x.second.begin(), x.second.end());
    for (long long i = 1; i < (long long)x.second.size(); i++)
      add(x.first, x.second[i], x.first, x.second[i - 1]);
  }
  for (auto &y : Y) {
    sort(y.second.begin(), y.second.end());
    for (long long i = 1; i < (long long)y.second.size(); i++)
      add(y.second[i], y.first, y.second[i - 1], y.first);
  }
  tv[0] = 1LL;
  for (long long i = 1; i < N; i++) tv[i] = (tv[i - 1] * 1LL * 2LL) % mod;
  for (auto x : nodes)
    if (!B[x]) {
      f = 1;
      XX.clear(), YY.clear();
      DFS(x);
      ans =
          (ans * 1LL * (tv[(long long)XX.size() + (long long)YY.size()] - f)) %
          mod;
    }
  printf("%I64d", ans);
}
