#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1123456;
const long long MOD = 1123456769;
const long long MAXANS = 1000000007;
using namespace std;
long long f[MAXN], now = 0, step[MAXN], X[MAXN], Y[MAXN], m[MAXN];
vector<long long> ss[MAXN], vx[MAXN], vy[MAXN];
pair<long long, long long> x[MAXN], y[MAXN];
void dfs(long long v) {
  if (f[v]) return;
  f[v] = now;
  for (long long i = 0; i < ss[v].size(); i++) dfs(ss[v][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  long long n, i, j, ans = 1, k;
  cin >> n;
  step[0] = 1;
  for (i = 1; i <= 2 * n; i++) (step[i] = step[i - 1] * 2) %= MAXANS;
  for (i = 1; i <= n; i++) {
    cin >> x[i].first >> y[i].first;
    X[i] = x[i].first;
    Y[i] = y[i].first;
    x[i].second = i;
    y[i].second = i;
  }
  sort(x + 1, x + n + 1);
  sort(y + 1, y + n + 1);
  for (i = 1; i < n; i++) {
    if (x[i].first == x[i + 1].first)
      ss[x[i].second].push_back(x[i + 1].second),
          ss[x[i + 1].second].push_back(x[i].second);
    if (y[i].first == y[i + 1].first)
      ss[y[i].second].push_back(y[i + 1].second),
          ss[y[i + 1].second].push_back(y[i].second);
  }
  for (i = 1; i <= n; i++)
    if (!f[i]) {
      ++now;
      dfs(i);
    }
  for (i = 1; i <= n; i++)
    m[f[i]] += ss[i].size(), vx[f[i]].push_back(X[i]), vy[f[i]].push_back(Y[i]);
  for (i = 1; i <= n; i++) {
    sort(vx[i].begin(), vx[i].end());
    sort(vy[i].begin(), vy[i].end());
    k = 0;
    m[i] /= 2;
    for (j = 0; j < vx[i].size(); j++)
      if (!j)
        ++k;
      else if (vx[i][j] != vx[i][j - 1])
        ++k;
    for (j = 0; j < vy[i].size(); j++)
      if (!j)
        ++k;
      else if (vy[i][j] != vy[i][j - 1])
        ++k;
    if (m[i] >= vx[i].size())
      ans *= step[k];
    else
      ans *= step[k] - 1;
    ans %= MAXANS;
  }
  cout << ans << "\n";
  return 0;
}
