#include <bits/stdc++.h>
using namespace std;
int n, x[100010], y[100010], rx[100010], ry[100010], l1, l2;
int f[200010], g[200010], size[200010];
inline int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
inline void merge(int x, int y) {
  y += l1;
  int fx = find(x), fy = find(y);
  if (fx == fy)
    g[fx] |= 1;
  else {
    f[fx] = fy;
    size[fy] += size[fx];
    g[fy] |= g[fx];
  }
}
inline int Pow(int x, int y) {
  int ans = 1, t = x;
  while (y > 0) {
    if (y & 1) ans = 1ll * ans * t % 1000000007;
    t = 1ll * t * t % 1000000007;
    y = y >> 1;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    rx[++l1] = x[i];
    ry[++l2] = y[i];
  }
  sort(rx + 1, rx + l1 + 1);
  sort(ry + 1, ry + l2 + 1);
  l1 = unique(rx + 1, rx + l1 + 1) - rx - 1;
  l2 = unique(ry + 1, ry + l2 + 1) - ry - 1;
  int m = l1 + l2;
  for (int i = 1; i <= m; i++) f[i] = i, g[i] = 0, size[i] = 1;
  for (int i = 1; i <= n; i++) {
    x[i] = lower_bound(rx + 1, rx + l1 + 1, x[i]) - rx;
    y[i] = lower_bound(ry + 1, ry + l2 + 1, y[i]) - ry;
    merge(x[i], y[i]);
  }
  int ans = 1;
  for (int i = 1; i <= m; i++)
    if (f[i] == i) {
      if (g[i] == 1)
        ans = 1ll * ans * Pow(2, size[i]) % 1000000007;
      else
        ans = 1ll * ans * (Pow(2, size[i]) - 1) % 1000000007;
    }
  cout << ans << endl;
  return 0;
}
