#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
int n, t, w, x[N], y[N], a[N], b[N], p[N], f[N], s[N], d[N];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &x[i], &y[i]), a[++t] = x[i], b[++w] = y[i];
  sort(a + 1, a + 1 + t), t = unique(a + 1, a + 1 + n) - a - 1,
                          sort(b + 1, b + 1 + w),
                          w = unique(b + 1, b + 1 + n) - b - 1;
  p[0] = 1;
  for (int i = 1; i <= t + w; i++)
    s[i] = 1, f[i] = i, p[i] = p[i - 1] * 2 % mod;
  for (int i = 1; i <= n; i++)
    x[i] = lower_bound(a + 1, a + 1 + t, x[i]) - a,
    y[i] = lower_bound(b + 1, b + 1 + w, y[i]) - b;
  for (int i = 1; i <= n; i++) {
    int xx = find(x[i]), yy = find(y[i] + t);
    if (xx != yy)
      f[xx] = yy, s[yy] += s[xx], d[yy] += d[xx] + 1;
    else
      d[xx]++;
  }
  long long ans = 1;
  for (int i = 1; i <= t + w; i++)
    if (find(i) == i)
      d[i] + 1 == s[i] ? (ans *= p[s[i]] - 1) %= mod : (ans *= p[s[i]]) %= mod;
  return printf("%lld\n", ans), 0;
}
