#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> vis, color;
map<int, vector<int>> xs, ys;
int findx(int x, int y) {
  vector<int> &s = ys[y];
  int l = 1, r = s.size() - 1, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (s[mid] >= x)
      r = mid;
    else
      l = mid + 1;
  }
  return r;
}
int findy(int x, int y) {
  vector<int> &s = xs[x];
  int l = 1, r = s.size() - 1, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (s[mid] >= y)
      r = mid;
    else
      l = mid + 1;
  }
  return r;
}
int cnt = 0;
int cp_p[100050], cp_line[100050];
set<int> numx, numy;
int di[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
void dfs(int x, int y) {
  cp_p[cnt]++;
  numx.insert(x);
  numy.insert(y);
  vis[{x, y}] = 1;
  color[{x, y}] = cnt;
  int cx = findx(x, y);
  int cy = findy(x, y);
  for (int d = (0); d <= (3); ++d) {
    int nex = cx + di[d][0];
    int ney = cy + di[d][1];
    if (nex > 0 && ney > 0 && nex < ys[y].size() && ney < xs[x].size()) {
      if (!vis[{ys[y][nex], xs[x][ney]}]) {
        dfs(ys[y][nex], xs[x][ney]);
      }
    }
  }
}
const long long md = 1e9 + 7;
const int MX = 400111;
long long fac[MX], facinv[MX], inv[MX];
inline long long C(long long x, long long y) {
  return fac[x] * facinv[y] % md * facinv[x - y] % md;
}
void ini() {
  fac[0] = 1LL, facinv[0] = 1LL;
  inv[1] = 1LL;
  for (long long i = 2; i <= 400000; i++)
    inv[i] = (md - md / i) * inv[md % i] % md;
  for (long long i = 1; i <= 400000; i++) fac[i] = fac[i - 1] * i % md;
  for (long long i = 1; i <= 400000; i++)
    facinv[i] = facinv[i - 1] * inv[i] % md;
}
int main() {
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  int n, x, y;
  memset(cp_p, 0, sizeof(cp_p));
  memset(cp_line, 0, sizeof(cp_line));
  ini();
  cin >> n;
  vector<pair<int, int>> vet;
  for (int i = (1); i <= (n); ++i) {
    cin >> x >> y;
    if (xs[x].size() == 0) xs[x].push_back(-2139062143);
    if (ys[y].size() == 0) ys[y].push_back(-2139062143);
    xs[x].push_back(y), ys[y].push_back(x);
    vet.push_back({x, y});
  }
  for (auto v : xs) sort(xs[v.first].begin(), xs[v.first].end());
  for (auto v : ys) sort(ys[v.first].begin(), ys[v.first].end());
  long long ans = 1;
  for (auto v : vet) {
    if (!vis[{v.first, v.second}]) {
      numx.clear(), numy.clear();
      dfs(v.first, v.second);
      cp_line[cnt] = numx.size() + numy.size();
      long long tmp = 0;
      for (int k = 0;
           k <= (cp_p[cnt] < cp_line[cnt] ? cp_p[cnt] : cp_line[cnt]); k++)
        tmp = (tmp + C(cp_line[cnt], k)) % md;
      ans = (ans * tmp) % md;
      cnt++;
    }
  }
  cout << ans << '\n';
  return 0;
}
