#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int x[100000], y[100000];
vector<pair<int, int> > xx[100000], yy[100000];
vector<int> v[100000];
bool chk[100000];
set<int> XX, YY;
long long pow2[200001];
int sz, deg;
void dfs(int N) {
  chk[N] = 1;
  sz++;
  deg += v[N].size();
  XX.insert(x[N]);
  YY.insert(y[N]);
  for (int next : v[N]) {
    if (!chk[next]) dfs(next);
  }
}
int main() {
  pow2[0] = 1;
  for (int(i) = (1); (i) <= (200000); (i) += (1))
    pow2[i] = (pow2[i - 1] << 1) % MOD;
  int n;
  scanf("%d", &n);
  vector<int> vx, vy;
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    scanf("%d%d", x + i, y + i);
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
  vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    x[i] = lower_bound(vx.begin(), vx.end(), x[i]) - vx.begin();
    y[i] = lower_bound(vy.begin(), vy.end(), y[i]) - vy.begin();
    xx[x[i]].push_back(make_pair(y[i], i));
    yy[y[i]].push_back(make_pair(x[i], i));
  }
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    sort(xx[i].begin(), xx[i].end());
    sort(yy[i].begin(), yy[i].end());
    for (int(j) = (1); (j) <= ((int)xx[i].size() - 1); (j) += (1)) {
      int a = xx[i][j - 1].second, b = xx[i][j].second;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    for (int(j) = (1); (j) <= ((int)yy[i].size() - 1); (j) += (1)) {
      int a = yy[i][j - 1].second, b = yy[i][j].second;
      v[a].push_back(b);
      v[b].push_back(a);
    }
  }
  long long ans = 1;
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    if (!chk[i]) {
      XX.clear();
      YY.clear();
      sz = deg = 0;
      dfs(i);
      long long k = pow2[XX.size() + YY.size()];
      if (deg / 2 == sz - 1) k--;
      ans = (ans * k) % MOD;
    }
  }
  printf("%lld", ans);
}
