#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9, P = 1e9 + 7;
int n, f[N], x[N], y[N], h[N], t, er[N], size[N], ans = 1;
bool s[N];
int find(int x) {
  while (x != f[x]) x = f[x] = f[f[x]];
  return x;
}
int main() {
  scanf("%d", &n);
  er[0] = 1;
  for (int i = 1; i <= (n << 1); ++i) er[i] = er[i - 1] * 2 % P;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    h[++t] = x[i] - 1e9 - 1;
    h[++t] = y[i] + 1e9;
  }
  sort(h + 1, h + t + 1);
  t = unique(h + 1, h + t + 1) - h - 1;
  for (int i = t; i; --i) f[i] = i, size[i] = 1;
  for (int i = 1, x, y; i <= n; ++i) {
    x = find(::x[i] = lower_bound(h + 1, h + t + 1, ::x[i] - 1e9 - 1) - h);
    y = find(::y[i] = lower_bound(h + 1, h + t + 1, ::y[i] + 1e9) - h);
    if (x == y)
      s[x] = 1;
    else
      f[x] = y, s[y] |= s[x], size[y] += size[x];
  }
  for (int i = 1, ret; i <= t; ++i)
    if (f[i] == i) {
      ret = er[size[i]];
      if (!s[i]) ret -= 1;
      ans = 1ll * ans * ret % P;
    }
  printf("%d\n", ans);
  return 0;
}
