#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int mod = 1e9 + 7;
int pw2[N];
int p[N];
int n;
pair<int, int> a[N];
map<int, vector<int> > allx;
map<int, vector<int> > ally;
map<int, set<int> > subx;
map<int, set<int> > suby;
int cyc[N];
int cnt[N];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y)
    cyc[x] = 1;
  else {
    p[x] = y;
  }
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i < N; i++) pw2[i] = pw2[i - 1] * 2 % mod;
  for (int i = 0; i < N; i++) p[i] = i;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = make_pair(x, y);
    allx[x].push_back(i);
    ally[y].push_back(i);
  }
  for (auto u : allx) {
    int xcoord = u.first;
    vector<int> &ind = u.second;
    for (int i = 0; i < ind.size() - 1; i++) {
      merge(ind[i], ind[i + 1]);
    }
  }
  for (auto u : ally) {
    int xcoord = u.first;
    vector<int> &ind = u.second;
    for (int i = 0; i < ind.size() - 1; i++) {
      merge(ind[i], ind[i + 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    cnt[find(i)]++;
    cyc[find(i)] |= cyc[i];
    subx[find(i)].insert(a[i].first);
    suby[find(i)].insert(a[i].second);
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (i == find(i)) {
      int sz = subx[i].size() + suby[i].size();
      if (cyc[i])
        ans = ans * pw2[sz] % mod;
      else
        ans = ans * (pw2[sz] - 1 + mod) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
