#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int N = 200002;
pair<int, int> arr[N];
vector<int> adj[N];
int n, cc, done[N];
long long fac[N], invFac[N];
map<int, int> compress;
long long C(int n, int r) {
  if (r < 0 || r > n) return 0;
  long long ans = fac[n];
  ans = (ans * invFac[r]) % (1000000007LL);
  ans = (ans * invFac[n - r]) % (1000000007LL);
  return ans;
}
set<int> points_;
long long calc(int v) {
  queue<int> qq;
  done[v] = 1;
  qq.push(v);
  points_.clear();
  int sz = 1;
  while (!qq.empty()) {
    int v = qq.front();
    qq.pop();
    for (auto it : adj[v]) {
      points_.insert(it);
      if (!done[arr[it].first]) {
        sz++;
        done[arr[it].first] = 1;
        qq.push(arr[it].first);
      }
      if (!done[arr[it].second]) {
        sz++;
        done[arr[it].second] = 1;
        qq.push(arr[it].second);
      }
    }
  }
  int lines = sz, points = (int)points_.size();
  long long ans = 0;
  for (int i = 0; i <= points; i++) ans = (ans + C(lines, i)) % (1000000007LL);
  return ans;
}
int main() {
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = (i * fac[i - 1]) % (1000000007LL);
    invFac[i] = pwr(fac[i], (1000000007LL) - 2);
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &arr[i].first, &arr[i].second);
    arr[i].first += (1000000007LL);
    arr[i].second -= (1000000007LL);
    compress[arr[i].first];
    compress[arr[i].second];
  }
  cc = 0;
  for (auto &it : compress) it.second = ++cc;
  for (int i = 1; i <= n; i++) {
    arr[i] = pair<int, int>(compress[arr[i].first], compress[arr[i].second]);
    adj[arr[i].first].push_back(i);
    adj[arr[i].second].push_back(i);
  }
  long long ans = 1;
  for (int i = 1; i <= cc; i++)
    if (!done[i]) ans = (ans * calc(i)) % (1000000007LL);
  printf("%lld\n", ans);
  return 0;
}
