#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
int Read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int t, n;
int x[300010], y[300010], p[300010];
map<int, int> rx, ry, visx, visy;
vector<int> v[300010];
const long long mod = 1e9 + 7;
long long ans;
long long fac[300010 << 1], ni[300010 << 1];
long long Quick(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1, a = a * a % mod;
  }
  return ans;
}
int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }
void Init() {
  fac[0] = 1, ni[0] = 1;
  for (int i = 1; i <= 2 * n + 1; i++)
    fac[i] = fac[i - 1] * i % mod, ni[i] = Quick(fac[i], mod - 2);
}
namespace Mod {
long long add(long long x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
long long minus(long long x, long long y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
long long mul(long long x, long long y) {
  x *= y;
  if (x >= mod) x %= mod;
  return x;
}
}  // namespace Mod
long long C(int a, int b) { return fac[a] * ni[b] % mod * ni[a - b] % mod; }
int main() {
  scanf("%d", &n);
  Init();
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    scanf("%d%d", &x[i], &y[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!rx[x[i]])
      rx[x[i]] = i;
    else {
      int px = Find(i), qx = Find(rx[x[i]]);
      p[px] = qx;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!ry[y[i]])
      ry[y[i]] = i;
    else {
      int py = Find(i), qy = Find(ry[y[i]]);
      p[py] = qy;
    }
  }
  for (int i = 1; i <= n; i++) {
    p[i] = Find(i);
    v[p[i]].push_back(i);
  }
  ans = 1;
  for (int i = 1; i <= n; i++) {
    if (v[i].size()) {
      int cnt = 0;
      long long tans = 0;
      for (int j = 0; j < v[i].size(); j++) {
        if (!visx[x[v[i][j]]]) visx[x[v[i][j]]] = 1, cnt++;
        if (!visy[y[v[i][j]]]) visy[y[v[i][j]]] = 1, cnt++;
      }
      for (int j = 0; j <= min((int)v[i].size(), cnt); j++) {
        tans = (tans + C(cnt, j)) % mod;
      }
      ans = ans * tans % mod;
      for (int j = 0; j < v[i].size(); j++) {
        visx[x[v[i][j]]] = 0;
        visy[y[v[i][j]]] = 0;
      }
    }
  }
  printf("%I64d\n", (ans % mod + mod) % mod);
  return 0;
}
