#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
vector<int> G[200005];
long long dp[200005][2];
int vis[200005];
int cnt = 0;
long long power(int T) {
  if (T == 0) return 1LL;
  long long pre = power(T >> 1);
  pre = pre * pre % INF;
  if (T & 1) pre = (pre + pre) % INF;
  return pre;
}
bool dfs(int v, int par) {
  vis[v] = 1;
  cnt++;
  bool ans = false;
  for (int k = 0; k < (G[v].size()); k++) {
    int u = G[v][k];
    if (vis[u] == 0 && dfs(u, v))
      ans = true;
    else if (vis[u] == 1 && u != par)
      ans = true;
  }
  vis[v] = -1;
  return ans;
}
map<int, int> xs, ys;
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int k = 0; k < (n); k++) {
    scanf("%d%d", &x, &y);
    int cx = xs.find(x) == xs.end() ? (xs[x] = cnt++) : xs[x];
    int cy = ys.find(y) == ys.end() ? (ys[y] = cnt++) : ys[y];
    G[cx].push_back(cy);
    G[cy].push_back(cx);
  }
  n = cnt;
  long long ans = 1LL;
  for (int k = 0; k < (n); k++)
    if (!vis[k]) {
      cnt = 0;
      if (dfs(k, -1))
        ans = ans * power(cnt) % INF;
      else
        ans = ans * (power(cnt) - 1 + INF) % INF;
    }
  printf("%I64d\n", ans);
  return 0;
}
