#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
using namespace std;
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 1e5;
const long long mod = 1e9 + 7;
map<long long, bool> visited;
map<long long, vector<long long> > nei;
int n;
long long two_pow[2 * N + 1];
bool ok;
long long dfs(long long v, long long par) {
  (v);
  visited[v] = true;
  long long res = 1;
  for (auto& w : nei[v]) {
    if (!visited[w]) {
      res += dfs(w, v);
    } else if (w != par) {
      ok = true;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long _ = (long long)0; _ < (long long)n; _++) {
    long long t1, t2;
    cin >> t1 >> t2;
    t2 += IINF;
    nei[t1].push_back(t2);
    nei[t2].push_back(t1);
  }
  two_pow[0] = 1;
  for (long long i = (long long)1; i < (long long)2 * N + 1; i++) {
    two_pow[i] = (two_pow[i - 1] * 2) % mod;
  }
  long long res = 1;
  for (auto& p : nei) {
    if (!visited[p.first]) {
      ok = false;
      long long sz = dfs(p.first, INF);
      (sz, two_pow[sz]);
      if (ok) {
        res = (res * two_pow[sz]) % mod;
      } else {
        res = (res * (mod + two_pow[sz] - 1)) % mod;
      }
    }
  }
  cout << res << "\n";
  return 0;
}
