#include <bits/stdc++.h>
using namespace std;
int x[200100], y[200100];
vector<int> e[200100];
set<int> s;
unordered_map<int, int> tx, ty;
int vis[200100], fa[200100], t, f;
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  t++;
  for (int i = 0; i < e[x].size(); i++) {
    int k = e[x][i];
    if (k == fa[x]) continue;
    if (vis[k]) {
      f = 1;
      continue;
    }
    fa[k] = x;
    dfs(k);
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) s.insert(x[i]);
  int cnt = 0;
  for (auto l = s.begin(); l != s.end(); ++l) tx[*l] = cnt++;
  for (int i = 0; i < n; i++) x[i] = tx[x[i]];
  s.clear();
  for (int i = 0; i < n; i++) s.insert(y[i]);
  for (auto l = s.begin(); l != s.end(); ++l) ty[*l] = cnt++;
  for (int i = 0; i < n; i++) y[i] = ty[y[i]];
  s.clear();
  for (int i = 0; i < n; i++) {
    e[x[i]].push_back(y[i]);
    e[y[i]].push_back(x[i]);
  }
  memset(fa, -1, sizeof(fa));
  long long ans = 1;
  for (int i = 0; i < cnt; i++) {
    t = f = 0;
    if (vis[i]) continue;
    dfs(i);
    long long w = 1;
    for (int i = 0; i < t; i++) w = (w * 2) % 1000000007;
    if (f == 0) w--;
    ans = (ans * w) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}
