#include <bits/stdc++.h>
using namespace std;
const long long int modulo = 1e9 + 7;
map<pair<int, int>, vector<pair<int, int> > > g;
set<pair<int, int> > visto;
void calcula(pair<int, int> u, pair<int, int> p, int &amount, int &hayciclo) {
  if (visto.count(u)) {
    hayciclo = 1;
    return;
  }
  visto.insert(u);
  amount++;
  vector<pair<int, int> > &ar = g[u];
  for (int i = 0; i < int(ar.size()); i++) {
    pair<int, int> v = ar[i];
    if (v != p) calcula(v, u, amount, hayciclo);
  }
}
const int limite = 1000000;
long long int expo[limite];
int main() {
  expo[0] = 1;
  for (int i = 1; i < limite; i++) expo[i] = expo[i - 1] * 2 % modulo;
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    pair<int, int> c(0, x);
    pair<int, int> f(1, y);
    g[f].push_back(c);
    g[c].push_back(f);
  }
  long long int sol = 1;
  for (map<pair<int, int>, vector<pair<int, int> > >::iterator it = g.begin();
       it != g.end(); it++) {
    pair<int, int> u = it->first;
    if (visto.count(u) == 0) {
      int amount = 0;
      int hayciclo = 0;
      calcula(u, pair<int, int>(-1, 0), amount, hayciclo);
      if (hayciclo)
        sol = (sol * expo[amount] % modulo);
      else
        sol = sol * (expo[amount] - 1) % modulo;
    }
  }
  sol = (sol % modulo + modulo) % modulo;
  cout << sol << endl;
}
