#include <bits/stdc++.h>
using namespace std;
struct line {
  vector<int> nei;
  bool vis = 0;
};
map<pair<int, int>, int> mp;
line A[200005];
int cnt;
int n, x, y;
long long ans = 1, MD = 1e9 + 7;
pair<long long, long long> dfs(int x) {
  if (A[x].vis) return {0, 0};
  A[x].vis = 1;
  int a = 1, b = A[x].nei.size();
  for (int y : A[x].nei) {
    auto z = dfs(y);
    a += z.first;
    b += z.second;
  }
  return {a, b};
}
long long pw(long long a, long long b) {
  if (b == 0) return 1;
  return ((b % 2 ? a : 1) * pw((a * a) % MD, b / 2)) % MD;
}
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    int X, Y;
    if (mp.count({x, 0}))
      X = mp[{x, 0}];
    else {
      mp[{x, 0}] = cnt++;
      X = cnt - 1;
    }
    if (mp.count({y, 1}))
      Y = mp[{y, 1}];
    else {
      mp[{y, 1}] = cnt++;
      Y = cnt - 1;
    }
    A[X].nei.push_back(Y);
    A[Y].nei.push_back(X);
  }
  for (int i = 0; i < cnt; i++) {
    auto x = dfs(i);
    if (x == make_pair(0ll, 0ll)) continue;
    if (x.first * 2 > x.second) {
      ans *= pw(2, x.first) - 1;
      ans %= MD;
    } else {
      ans *= pw(2, x.first);
      ans %= MD;
    }
  }
  cout << ans << endl;
}
