#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200200];
int mod = 1000000007;
long long sol = 1;
long long p2[200200];
int n;
int a, b;
int nd = 0;
map<int, int> x, y;
bool vis[200200];
bool ok = true;
int cnt = 0;
void is_tree(int nd, int p) {
  vis[nd] = true;
  cnt++;
  for (int i = 0; i < adj[nd].size(); i++) {
    int ch = adj[nd][i];
    if (ch == p) continue;
    if (vis[ch]) {
      ok = false;
    } else {
      is_tree(ch, nd);
    }
  }
}
int main() {
  p2[0] = 1;
  for (int i = 1; i < 200200; i++) {
    p2[i] = (2 * p2[i - 1]) % mod;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (!x.count(a)) {
      x[a] = nd++;
    }
    if (!y.count(b)) {
      y[b] = nd++;
    }
    a = x[a];
    b = y[b];
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < nd; i++) {
    cnt = 0;
    ok = true;
    if (vis[i]) continue;
    is_tree(i, i);
    if (!ok) {
      sol *= p2[cnt];
    } else {
      sol *= p2[cnt] - 1;
    }
    sol %= mod;
  }
  cout << sol << endl;
}
