#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 200105;
const double PI = acos(-1.0);
const double eps = 1e-6;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
int n, x, y, nx = 0, ny = 0, t, dn, en, p[N], q[N];
vector<int> V[N];
map<int, int> X, Y;
bool v[N];
long long ans = 1, base[N];
void dfs(int x) {
  v[x] = 1;
  dn++, en += V[x].size();
  for (__typeof((V[x]).begin()) it = (V[x]).begin(); it != (V[x]).end(); it++)
    if (!v[*it]) dfs(*it);
}
int main() {
  scanf("%d", &n);
  base[0] = 1;
  for (int i = (1); i <= (n); ++i) {
    scanf("%d%d", &x, &y);
    if (!X[x]) X[x] = ++nx;
    if (!Y[y]) Y[y] = ++ny;
    p[i] = X[x], q[i] = Y[y];
  }
  for (int i = (1); i <= (n); ++i)
    V[p[i]].push_back(q[i] + nx), V[q[i] + nx].push_back(p[i]);
  for (int i = (1); i <= (2 * n); ++i) base[i] = base[i - 1] * 2 % _p;
  for (int i = (1); i <= (nx + ny); ++i) {
    if (v[i]) continue;
    dn = en = 0;
    dfs(i);
    (ans *= (base[dn] - (dn - en / 2 == 1))) %= _p;
  }
  printf("%I64d\n", ans);
  return 0;
}
