#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5], b[200000 + 5];
vector<int> va, vb;
void quchong(vector<int> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
int getaid(int x) {
  return lower_bound(va.begin(), va.end(), x) - va.begin() + 1;
}
int getbid(int x) {
  return lower_bound(vb.begin(), vb.end(), x) - vb.begin() + 1;
}
int fa[200000 + 5], sz[200000 + 5];
bool mark[200000 + 5];
int getfa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getfa(fa[x]);
}
long long qp(long long a, int k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    k >>= 1;
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
  for (int i = 1; i <= n; i++) va.push_back(a[i]);
  for (int i = 1; i <= n; i++) vb.push_back(b[i]);
  quchong(va);
  quchong(vb);
  int N = va.size(), M = vb.size();
  for (int i = 1; i <= N + M; i++) fa[i] = i;
  for (int i = 1; i <= N + M; i++) sz[i] = 1;
  for (int i = 1; i <= n; i++) {
    int x = getaid(a[i]);
    int y = N + getbid(b[i]);
    int fx = getfa(x), fy = getfa(y);
    if (fx == fy)
      mark[fx] = 1;
    else {
      sz[fx] += sz[fy];
      mark[fx] |= mark[fy];
      fa[fy] = fx;
    }
  }
  long long ans = 1;
  for (int i = 1; i <= N + M; i++)
    if (i == getfa(i)) ans = ans * (qp(2, sz[i]) - (mark[i] == 0)) % 1000000007;
  printf("%I64d\n", ans);
  return 0;
}
