#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int power(int a, int b, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % mod)
    if (b & 1) ans = 1LL * ans * a % mod;
  return ans;
}
const int NN = 100100;
int x[NN], y[NN], MA[NN], MB[NN];
set<int> A, B;
vector<int> h[NN], s[NN];
bool fl[NN];
queue<int> q;
int cnt;
void bfs() {
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    A.insert(x[id]);
    B.insert(y[id]);
    for (int u : h[x[id]]) {
      if (fl[u]) continue;
      cnt++;
      fl[u] = 1;
      q.push(u);
    }
    for (int u : s[y[id]]) {
      if (fl[u]) continue;
      cnt++;
      fl[u] = 1;
      q.push(u);
    }
    h[x[id]].clear();
    s[y[id]].clear();
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", x + i, y + i);
    MA[i] = x[i];
    MB[i] = y[i];
  }
  int a = n, b = n;
  sort(MA + 1, MA + a + 1);
  sort(MB + 1, MB + b + 1);
  a = unique(MA + 1, MA + a + 1) - MA;
  b = unique(MB + 1, MB + b + 1) - MB;
  for (int i = 1; i <= n; i++) {
    x[i] = lower_bound(MA + 1, MA + a + 1, x[i]) - MA;
    y[i] = lower_bound(MB + 1, MB + b + 1, y[i]) - MB;
    h[x[i]].push_back(i);
    s[y[i]].push_back(i);
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    if (fl[i]) continue;
    cnt = 1;
    q.push(i);
    fl[i] = 1;
    bfs();
    int hh = A.size(), ss = B.size();
    A.clear();
    B.clear();
    if (cnt >= hh + ss)
      ans = ans * power(2, hh + ss) % mod;
    else
      ans = ans * (power(2, hh + ss) - 1) % mod;
    ans %= mod;
  }
  ans = (ans + mod) % mod;
  printf("%d\n", ans);
  return 0;
}
