#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
struct point {
  long long x, y, id;
  bool operator<(const point &rhs) const { return x < rhs.x; }
} p[200050];
long long n, fa[200050], cir[200050];
inline long long Find(long long x) {
  return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
inline void Merge(long long x, long long y) {
  long long fx = Find(x);
  long long fy = Find(y);
  if (fx == fy)
    cir[fx] = 1;
  else {
    fa[fy] = fx;
    cir[fx] |= cir[fy];
  }
}
set<long long> sx[200050], sy[200050];
const long long mod = 1e9 + 7;
inline long long quickpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return ans;
}
int main() {
  n = read();
  for (long long i = 1; i <= n; i++) {
    p[i].x = read();
    p[i].y = read();
    p[i].id = i;
    fa[i] = i;
  }
  sort(p + 1, p + n + 1);
  for (long long i = 2; i <= n; i++)
    if (p[i].x == p[i - 1].x) Merge(p[i].id, p[i - 1].id);
  for (long long i = 1; i <= n; i++) swap(p[i].x, p[i].y);
  sort(p + 1, p + n + 1);
  for (long long i = 2; i <= n; i++)
    if (p[i].x == p[i - 1].x) Merge(p[i].id, p[i - 1].id);
  for (long long i = 1; i <= n; i++) {
    long long fx = Find(p[i].id);
    sx[fx].insert(p[i].x);
    sy[fx].insert(p[i].y);
  }
  long long ans = 1;
  for (long long i = 1; i <= n; i++)
    if (Find(i) == i)
      ans = 1LL * ans *
            (quickpow(2, sx[i].size() + sy[i].size()) - (cir[i] ^ 1)) % mod;
  cout << (ans + mod) % mod << endl;
  return 0;
}
