#include <bits/stdc++.h>
using namespace std;
int N;
pair<int, int> P[200005];
vector<int> G[200005];
map<int, int> X[2];
const int MOD = 1000000007;
int cnt;
bool Use[200005];
int aux, cycle;
int powerLog(int n, int p) {
  int sol = 1;
  while (p) {
    if (p % 2 == 1) sol = (1LL * sol * n) % MOD;
    p /= 2;
    n = (1LL * n * n) % MOD;
  }
  return sol;
}
void Read() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int node1, node2;
    if (X[0].find(x) != X[0].end()) {
      node1 = X[0][x];
    } else {
      ++cnt;
      X[0][x] = cnt;
      node1 = cnt;
    }
    if (X[1].find(y) != X[1].end()) {
      node2 = X[1][y];
    } else {
      ++cnt;
      X[1][y] = cnt;
      node2 = cnt;
    }
    G[node1].push_back(node2);
    G[node2].push_back(node1);
  }
}
void DFS(int node, int father) {
  Use[node] = 1;
  aux++;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i];
    if (neighb == father) continue;
    if (Use[neighb] == 1) {
      cycle = 1;
    } else
      DFS(neighb, node);
  }
}
void Solve() {
  int ans = 1;
  for (int i = 1; i <= cnt; i++) {
    if (Use[i] == 0) {
      cycle = 0;
      aux = 0;
      DFS(i, 0);
      if (cycle == 1) {
        aux = powerLog(2, aux);
        ans = (1LL * ans * aux) % MOD;
      } else {
        aux = powerLog(2, aux);
        --aux;
        if (aux < 0) aux += MOD;
        ans = (1LL * ans * aux) % MOD;
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  Read();
  Solve();
  return 0;
}
