#include <bits/stdc++.h>
const long double PI = acos(-1);
const long double eps = 0.0000000001;
const long long INF = 0x3fffffffffffffff;
const long long MOD = 1000000007;
std::map<long long, long long> x, y;
long long fa[200005], siz[200005], ans, cnt, n;
bool huan[200005];
long long find(long long now) {
  return now == fa[now] ? now : fa[now] = find(fa[now]);
}
long long power(long long A, long long B) {
  long long res = 1;
  while (B) {
    if (B & 1) res = res * A % MOD;
    B >>= 1;
    A = A * A % MOD;
  }
  return res;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (long long i = 1; i <= n + n; ++i) fa[i] = i, siz[i] = 1;
  for (long long i = 1; i <= n; ++i) {
    static long long X, Y;
    std::cin >> X >> Y;
    if (!x[X]) x[X] = ++cnt;
    if (!y[Y]) y[Y] = ++cnt;
    if (find(x[X]) == find(y[Y]))
      huan[find(x[X])] = true;
    else {
      siz[find(x[X])] += siz[find(y[Y])];
      huan[find(x[X])] |= huan[find(y[Y])];
      fa[find(y[Y])] = find(x[X]);
    }
  }
  ans = 1;
  for (long long i = 1; i <= cnt; ++i)
    if (find(i) == i) ans = ans * (power(2, siz[i]) - !huan[i]) % MOD;
  std::cout << ans << std::endl;
  return 0;
}
