#include <bits/stdc++.h>
using namespace std;
long long n, v[100005], p[100005], ans = 1, mod = 1e9 + 7, fc[200005],
                                   inv[200005];
pair<long long, long long> a[100005];
vector<long long> g[100005], h[100005], t;
set<long long> s;
bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
long long pwr(long long a, long long p) {
  if (p == 0) return 1;
  long long t = pwr(a, p / 2);
  t = t * t % mod;
  if (p % 2)
    return t * a % mod;
  else
    return t;
}
long long Comb(long long n, long long k) {
  return fc[n] * inv[k] % mod * inv[n - k] % mod;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  fc[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= 2 * n; i++) {
    fc[i] = fc[i - 1] * i % mod;
    inv[i] = pwr(fc[i], mod - 2);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a + 1, a + n + 1, comp);
  int f = 0;
  for (int i = 1; i <= n; i++) {
    f++;
    while (a[i].second == a[i + 1].second && i < n) {
      a[i].second = f;
      i++;
    }
    a[i].second = f;
  }
  sort(a + 1, a + n + 1);
  f = 0;
  for (int i = 1; i <= n; i++) {
    f++;
    while (a[i].first == a[i + 1].first && i < n) {
      a[i].first = f;
      i++;
    }
    a[i].first = f;
  }
  for (int i = 1; i <= n; i++) {
    g[a[i].second].push_back(a[i].first);
    h[a[i].first].push_back(a[i].second);
  }
  for (int i = 1; i <= n; i++) {
    if (v[i]) continue;
    if (h[i].size() == 0) continue;
    long long cnt1 = 0, cnt2 = 0;
    t.clear();
    t.push_back(i);
    v[i] = 1;
    cnt1++;
    for (int j = 0; j < t.size(); j++) {
      for (int k : h[t[j]]) {
        if (!p[k]) {
          cnt2++;
          p[k] = 1;
          for (int q : g[k]) {
            if (!v[q]) {
              v[q] = 1;
              t.push_back(q);
              cnt1++;
            }
          }
        }
      }
    }
    long long cnt3 = 0;
    for (int i : t) cnt3 += h[i].size();
    long long xd = 0;
    for (int i = 0; i <= min(cnt1 + cnt2, cnt3); i++) {
      xd += Comb(cnt1 + cnt2, i);
      xd %= mod;
    }
    ans *= xd;
    ans %= mod;
  }
  cout << ans;
}
