#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int cnt, n;
int ans;
map<int, int> xx, yy;
int x[maxn], y[maxn];
int fa[maxn * 2];
int cnt1[maxn * 2], cnt2[maxn * 2];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int pow(int a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = 1LL * res * a % mod;
    a = 1LL * a * a % mod;
    b /= 2;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
  for (int i = 1; i <= n; i++) {
    if (!xx.count(x[i])) xx.insert(make_pair(x[i], ++cnt));
    if (!yy.count(y[i])) yy.insert(make_pair(y[i], ++cnt));
  }
  for (int i = 1; i <= cnt; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) fa[find(xx[x[i]])] = find(yy[y[i]]);
  for (int i = 1; i <= n; i++) cnt1[find(xx[x[i]])]++;
  for (int i = 1; i <= cnt; i++) cnt2[find(i)]++;
  ans = 1;
  for (int i = 1; i <= cnt; i++)
    if (fa[i] == i) {
      if (cnt1[i] + 1 == cnt2[i])
        ans = 1LL * (pow(2, cnt2[i]) - 1 + mod) * ans % mod;
      else
        ans = 1LL * pow(2, cnt2[i]) * ans % mod;
    }
  cout << ans << endl;
  return 0;
}
