#include <bits/stdc++.h>
using namespace std;
const long long N = 100005, M = 1e9 + 7;
map<long long, long long> Map1, Map2;
long long n, f[N], x[N], y[N];
vector<long long> v[N];
inline long long find(long long x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
inline long long ksm(long long x, long long y) {
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % M)
    if (y & 1) (ans *= x) %= M;
  return ans;
}
inline void link(long long x, long long y) { f[find(x)] = find(y); }
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) f[i] = i;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    if (Map1[x[i]]) link(i, Map1[x[i]]);
    if (Map2[y[i]]) link(i, Map2[y[i]]);
    Map1[x[i]] = i;
    Map2[y[i]] = i;
  }
  long long ans = 1;
  for (long long i = 1; i <= n; i++) v[find(i)].push_back(i);
  for (long long i = 1; i <= n; i++) {
    Map1.clear(), Map2.clear();
    long long cntx = 0, cnty = 0, cnt = 0;
    for (long long j : v[i]) {
      if (!Map1[x[j]]) Map1[x[j]] = 1, cntx++;
      if (!Map2[y[j]]) Map2[y[j]] = 1, cnty++;
      cnt++;
    }
    if (cntx + cnty > cnt)
      (ans *= ksm(2, cntx + cnty) - 1) %= M;
    else
      (ans *= ksm(2, cntx + cnty)) %= M;
  }
  printf("%lld\n", ans);
}
