#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1e9 + 7;
int n, cnt, res = 1;
int x[N], y[N];
bool visit[N * 2];
bool hasCycle;
vector<int> vx, vy;
vector<int> G[N * 2];
int pw(int x) {
  if (!x) return 1;
  int ret = pw(x >> 1);
  ret = 1LL * ret * ret % mod;
  if (x & 1) ret = 2 * ret % mod;
  return ret;
}
void dfs(int u, int p) {
  visit[u] = 1, cnt++;
  for (auto v : G[u]) {
    if (v == p) continue;
    if (visit[v]) {
      hasCycle = 1;
      continue;
    }
    dfs(v, u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    vx.push_back(x[i]), vy.push_back(y[i]);
  }
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  for (int i = 0; i < n; ++i) {
    x[i] = lower_bound(vx.begin(), vx.end(), x[i]) - vx.begin();
    y[i] = lower_bound(vy.begin(), vy.end(), y[i]) - vy.begin();
    G[x[i]].push_back(y[i] + n), G[y[i] + n].push_back(x[i]);
  }
  for (int i = 0; i < n * 2; ++i) {
    if (!visit[i] && G[i].size()) {
      hasCycle = cnt = 0, dfs(i, i);
      if (hasCycle)
        res = 1LL * res * pw(cnt) % mod;
      else
        res = 1LL * res * (pw(cnt) - 1 + mod) % mod;
    }
  }
  cout << res;
}
