#include <bits/stdc++.h>
using namespace std;
const int maxn = 100009;
const int mod = 1e9 + 7;
vector<int> to[maxn << 1];
long long a[maxn], b[maxn], t[maxn << 1];
int col[maxn << 1];
int n, e_sum, cnt, poi, edg;
long long ans = 1;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void dfs(int x) {
  poi++;
  col[x] = cnt;
  int sz = to[x].size();
  for (int i = 0; i < sz; i++) {
    int w = to[x][i];
    if (!col[w])
      dfs(w), edg++;
    else if (col[w] == cnt)
      edg++;
  }
}
long long PowerMod(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    t[++t[0]] = a[i] = read(), t[++t[0]] = b[i] = read() + 3e9;
  sort(t + 1, t + 1 + t[0]);
  t[0] = unique(t + 1, t + 1 + t[0]) - t - 1;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(t + 1, t + 1 + t[0], a[i]) - t;
    b[i] = lower_bound(t + 1, t + 1 + t[0], b[i]) - t;
    to[a[i]].push_back(b[i]);
    to[b[i]].push_back(a[i]);
  }
  for (int i = 1; i <= n; i++)
    if (!col[i]) {
      cnt++;
      poi = edg = 0;
      dfs(i);
      edg /= 2;
      if (edg < poi)
        ans = ans * (PowerMod(2, poi) - 1) % mod;
      else
        ans = ans * PowerMod(2, poi) % mod;
    }
  cout << ans << endl;
  return 0;
}
