#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long modpow(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> gr(n + 1);
  vector<pair<int, int>> vp(n + 1);
  map<int, vector<pair<int, int>>> vx, vy;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    vx[x].push_back({y, i});
    vy[y].push_back({x, i});
    vp[i] = {x, y};
  }
  for (auto p : vx) {
    auto v = p.second;
    sort(v.begin(), v.end());
    int sz = v.size();
    for (int i = 1; i < sz; i++) {
      gr[v[i].second].push_back(v[i - 1].second);
      gr[v[i - 1].second].push_back(v[i].second);
    }
  }
  for (auto p : vy) {
    auto v = p.second;
    sort(v.begin(), v.end());
    int sz = v.size();
    for (int i = 1; i < sz; i++) {
      gr[v[i].second].push_back(v[i - 1].second);
      gr[v[i - 1].second].push_back(v[i].second);
    }
  }
  vector<int> cc(n + 1);
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    if (cc[i]) continue;
    set<int> sx, sy;
    queue<int> q;
    q.push(i);
    cc[i] = i;
    int ect = 0, vct = 0;
    ;
    while (q.size()) {
      int cur = q.front();
      vct++;
      sx.insert(vp[cur].first);
      sy.insert(vp[cur].second);
      q.pop();
      for (int x : gr[cur]) {
        ect++;
        if (cc[x]) continue;
        cc[x] = i;
        q.push(x);
      }
    }
    ans *= modpow(2, sx.size() + sy.size(), MOD) - (ect == 2 * (vct - 1));
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
