#include <bits/stdc++.h>
using namespace std;
long long int Rank[200005];
long long int Parent[200005];
long long int Find(long long int i) {
  if (Parent[i] == i) {
    return i;
  } else {
    long long int result = Find(Parent[i]);
    Parent[i] = result;
    return result;
  }
}
void uni(long long int i, long long int j) {
  long long int irep = Find(i);
  long long int jrep = Find(j);
  if (irep == jrep) return;
  long long int irank = Rank[irep];
  long long int jrank = Rank[jrep];
  if (irank < jrank) {
    Parent[irep] = jrep;
  } else if (jrank < irank) {
    Parent[jrep] = irep;
  } else {
    Parent[irep] = jrep;
    Rank[jrep]++;
  }
}
pair<long long int, long long int> v[100005];
vector<pair<long long int, long long int> > p[100005];
long long int mod = 1000000007;
long long int po[300005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  po[0] = 1;
  for (long long int i = 1; i <= 300000; i++) {
    po[i] = po[i - 1] * 2;
    po[i] %= mod;
  }
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    Parent[i] = i;
  }
  map<long long int, vector<long long int> > xc;
  map<long long int, vector<long long int> > yc;
  map<long long int, vector<long long int> >::iterator it;
  for (long long int i = 1; i <= n; i++) {
    cin >> v[i].first >> v[i].second;
    xc[v[i].first].push_back(i);
    yc[v[i].second].push_back(i);
  }
  for (it = xc.begin(); it != xc.end(); it++) {
    for (long long int j = 0; j < (it->second).size(); j++) {
      uni((it->second)[0], (it->second)[j]);
    }
  }
  for (it = yc.begin(); it != yc.end(); it++) {
    for (long long int j = 0; j < (it->second).size(); j++) {
      uni((it->second)[0], (it->second)[j]);
    }
  }
  for (long long int i = 1; i <= n; i++) {
    p[Find(i)].push_back(v[i]);
  }
  long long int ans = 1;
  for (long long int i = 1; i <= n; i++) {
    if (p[i].size() == 0) {
      continue;
    }
    set<long long int> x;
    set<long long int> y;
    long long int c = p[i].size();
    for (long long int j = 0; j < p[i].size(); j++) {
      x.insert(p[i][j].first);
      y.insert(p[i][j].second);
    }
    long long int w = x.size() + y.size();
    if (w == c + 1) {
      ans *= po[w] - 1 + mod;
      ans %= mod;
    } else {
      ans *= po[w];
      ans %= mod;
    }
  }
  cout << ans;
}
