#include <bits/stdc++.h>
using namespace std;
namespace TYC {
const int N = 2e5 + 10;
const int p = 1e9 + 7;
int fa[N], tag[N], size[N];
inline int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int find(const int x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); }
inline long long pow2(long long tim) {
  long long ans = 1, x = 2;
  for (; tim; tim >>= 1, x = x * x % p)
    if (tim & 1) ans = ans * x % p;
  return ans;
}
void work() {
  int n = read();
  static int x[N], y[N], rx[N], ry[N];
  for (int i = 1; i <= n; i++) {
    rx[i] = x[i] = read();
    ry[i] = y[i] = read();
  }
  sort(rx + 1, rx + 1 + n);
  sort(ry + 1, ry + 1 + n);
  int tx = unique(rx + 1, rx + 1 + n) - rx - 1;
  int ty = unique(ry + 1, ry + 1 + n) - ry - 1;
  for (int i = 1; i <= tx + ty; i++) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= n; i++) {
    int u = lower_bound(rx + 1, rx + 1 + tx, x[i]) - rx;
    int v = lower_bound(ry + 1, ry + 1 + ty, y[i]) - ry;
    v += tx;
    int fu = find(u), fv = find(v);
    if (fu == fv)
      tag[fu] = 1;
    else {
      fa[fu] = fv;
      tag[fv] |= tag[fu];
      size[fv] += size[fu];
    }
  }
  static int vis[N];
  long long ans = 1;
  for (int i = 1; i <= tx + ty; i++) {
    int f = find(i);
    if (!vis[f]) {
      ans = ans * (pow2(size[f]) - (tag[f] != 1)) % p;
      vis[f] = 1;
    }
  }
  printf("%lld\n", ans);
}
}  // namespace TYC
int main() {
  TYC::work();
  return 0;
}
