#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int main(void) {
  int n;
  scanf("%i", &n);
  map<int, vector<int>> Y, X;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%i %i", &x, &y);
    Y[x].push_back(y);
    X[y].push_back(x);
  }
  for (auto &node : Y) {
    vector<int> &s = node.second;
    sort(begin(s), end(s));
  }
  for (auto &node : X) {
    vector<int> &s = node.second;
    sort(begin(s), end(s));
  }
  vector<long long> pw2(n + 11, 1);
  for (int i = 1; i <= n + 10; i++) {
    pw2[i] = (pw2[i - 1] * 2) % mod;
  }
  long long ans = 1;
  set<pair<int, int>> seen;
  for (auto node : Y) {
    int x = node.first;
    vector<int> s = node.second;
    for (int y : s) {
      if (seen.count(make_pair(x, y))) {
        continue;
      }
      set<int> Sx, Sy;
      queue<int> Q;
      Q.push(x);
      Q.push(y);
      seen.insert(make_pair(x, y));
      int m = 0;
      while (!Q.empty()) {
        m++;
        int cur_x = Q.front();
        Q.pop();
        int cur_y = Q.front();
        Q.pop();
        Sx.insert(cur_x);
        Sy.insert(cur_y);
        vector<int> &sx = X[cur_y];
        vector<int> &sy = Y[cur_x];
        vector<int> ch_x, ch_y;
        int it_y = lower_bound(begin(sy), end(sy), cur_y) - begin(sy);
        if (it_y + 1 < sy.size()) {
          ch_x.push_back(cur_x);
          ch_y.push_back(sy[it_y + 1]);
        }
        if (it_y - 1 >= 0) {
          ch_x.push_back(cur_x);
          ch_y.push_back(sy[it_y - 1]);
        }
        int it_x = lower_bound(begin(sx), end(sx), cur_x) - begin(sx);
        if (it_x + 1 < sx.size()) {
          ch_x.push_back(sx[it_x + 1]);
          ch_y.push_back(cur_y);
        }
        if (it_x - 1 >= 0) {
          ch_x.push_back(sx[it_x - 1]);
          ch_y.push_back(cur_y);
        }
        for (int i = 0; i < ch_x.size(); i++) {
          if (!seen.count(make_pair(ch_x[i], ch_y[i]))) {
            seen.insert(make_pair(ch_x[i], ch_y[i]));
            Q.push(ch_x[i]);
            Q.push(ch_y[i]);
          }
        }
      }
      long long nways = pw2[int(Sx.size() + Sy.size())];
      if (m < Sx.size() + Sy.size()) {
        nways = (nways + mod - 1) % mod;
      }
      ans = (ans * nways) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
