#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int ans = 1, n, sz, ed, pw[N << 1];
vector<int> gr[N << 1];
map<int, int> mpx, mpy;
bool mark[N << 1];
void dfs(int v) {
  mark[v] = 1, sz++, ed += gr[v].size();
  for (auto u : gr[v])
    if (!mark[u]) dfs(u);
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  pw[0] = 1;
  for (int i = 1; i <= 2 * n; i++) pw[i] = pw[i - 1] * 2 % mod;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (!mpx.count(x)) {
      int sz = mpx.size();
      mpx[x] = sz;
    }
    if (!mpy.count(y)) {
      int sz = mpy.size();
      mpy[y] = sz + n;
    }
    x = mpx[x], y = mpy[y];
    gr[x].push_back(y), gr[y].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      ed = sz = 0, dfs(i);
      ed /= 2;
      ans = 1ll * ans * (pw[sz] - (ed == sz - 1)) % mod;
    }
  }
  cout << ans;
  return 0;
}
