#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int father[200010], n, x[100010], y[100010], a[100010], cnt1, cnt;
long long size[200010], edge[200010], ans;
long long calc(long long a, long long b, int mod) {
  long long ans = 1, t = a;
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * t % mod;
    t = t * t % mod;
  }
  return ans;
}
int find(int x) {
  if (father[x] == x)
    return x;
  else
    return father[x] = find(father[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = 1; i <= n; i++) a[i] = x[i];
  sort(a + 1, a + n + 1);
  cnt1 = unique(a + 1, a + n + 1) - a;
  for (int i = 1; i <= n; i++) x[i] = lower_bound(a + 1, a + cnt1, x[i]) - a;
  for (int i = 1; i <= n; i++) a[i] = y[i];
  sort(a + 1, a + n + 1);
  cnt = unique(a + 1, a + n + 1) - a;
  for (int i = 1; i <= n; i++) y[i] = lower_bound(a + 1, a + cnt, y[i]) - a;
  for (int i = 1; i <= n * 2; i++) father[i] = i, size[i] = 1;
  cnt1--;
  for (int i = 1; i <= n; i++) {
    int rx = find(x[i]), ry = find(y[i] + cnt1);
    if (rx != ry)
      father[rx] = ry, size[ry] += size[rx], edge[ry] += edge[rx] + 1;
    else
      edge[ry]++;
  }
  ans = 1;
  for (int i = 1; i <= 2 * n; i++)
    if (father[i] == i)
      ans = ans * (calc(2LL, size[i], mod) + mod - (edge[i] == size[i] - 1)) %
            mod;
  printf("%lld\n", ans);
  return 0;
}
