#include <bits/stdc++.h>
using namespace std;
char buf[1 << 20], *p1 = buf, *p2 = buf;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
           ? EOF
           : *p1++);
  for (; !isdigit(c);
       c = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
                ? EOF
                : *p1++))
    if (c == '-') f = 0;
  if (f)
    for (; isdigit(c);
         c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),
                          p1 == p2)
                  ? EOF
                  : *p1++))
      x = x * 10 - 48 + c;
  else
    for (; isdigit(c);
         c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),
                          p1 == p2)
                  ? EOF
                  : *p1++))
      x = x * 10 + 48 - c;
}
template <typename T, typename... Args>
void read(T &t, Args &...args) {
  read(t), read(args...);
}
const int N = 2e5 + 5, p = 1e9 + 7;
int n, a[N], b[N];
int ind, fa[N], siz[N], ans = 1;
bool cir[N];
map<int, int> lshx, lshy;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y)
    cir[x] = 1;
  else
    fa[x] = y, siz[y] += siz[x], cir[y] += cir[x];
}
int Pow(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) res = (long long)res * x % p;
  return res;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i], b[i]);
    if (lshx.find(a[i]) == lshx.end()) lshx[a[i]] = ++ind;
    if (lshy.find(b[i]) == lshy.end()) lshy[b[i]] = ++ind;
  }
  for (int i = 1; i <= ind; ++i) fa[i] = i, siz[i] = 1;
  for (int i = 1; i <= n; ++i) merge(lshx[a[i]], lshy[b[i]]);
  for (int i = 1; i <= ind; ++i)
    if (find(i) == i) {
      if (cir[i])
        ans = (long long)ans * Pow(2, siz[i]) % p;
      else
        ans = ans * (Pow(2, siz[i]) - 1ll) % p;
    }
  printf("%d", ans);
  return 0;
}
