#include <bits/stdc++.h>
using namespace std;
int N;
int X[101010], Y[101010];
vector<int> XS, YS;
int RS[101010];
int CS[101010];
template <int um>
class UF {
 public:
  vector<int> par, rank, cnt;
  UF() {
    par = rank = vector<int>(um, 0);
    cnt = vector<int>(um, 1);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  void reinit() {
    int i;
    for (i = 0; i < (um); i++) rank[i] = 0, cnt[i] = 1, par[i] = i;
  }
  int operator[](int x) {
    return (par[x] == x) ? (x) : (par[x] = operator[](par[x]));
  }
  int count(int x) { return cnt[operator[](x)]; }
  int operator()(int x, int y) {
    if ((x = operator[](x)) == (y = operator[](y))) return x;
    cnt[y] = cnt[x] = cnt[x] + cnt[y];
    if (rank[x] > rank[y]) return par[x] = y;
    rank[x] += rank[x] == rank[y];
    return par[y] = x;
  }
};
UF<500000> uf;
vector<int> cand[502020];
signed long long p2[202020];
signed long long ret;
signed long long mo = 1000000007;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) {
    cin >> X[i] >> Y[i];
    XS.push_back(X[i]);
    YS.push_back(Y[i]);
  }
  p2[0] = 1;
  for (i = 0; i < (201000); i++) p2[i + 1] = p2[i] * 2 % mo;
  sort((XS.begin()), (XS.end()));
  sort((YS.begin()), (YS.end()));
  XS.erase(unique((XS.begin()), (XS.end())), XS.end());
  YS.erase(unique((YS.begin()), (YS.end())), YS.end());
  for (i = 0; i < (N); i++) {
    X[i] = lower_bound((XS.begin()), (XS.end()), X[i]) - XS.begin();
    Y[i] = lower_bound((YS.begin()), (YS.end()), Y[i]) - YS.begin();
    RS[Y[i]]++;
    CS[X[i]]++;
    uf(Y[i], 200000 + i);
    uf(100000 + X[i], 200000 + i);
  }
  for (i = 0; i < (200000 + N); i++) cand[uf[i]].push_back(i);
  ret = 1;
  for (i = 0; i < (200000 + N); i++)
    if (uf[i] == i) {
      int e = 0, v = 0, rc = 0;
      for (auto& c : cand[i]) {
        if (c < 100000)
          e += RS[c] - 1, rc++;
        else if (c < 200000)
          e += CS[c - 100000] - 1, rc++;
        else
          v++;
      }
      if (v == 0) continue;
      if (e >= v) {
        (ret *= p2[rc]) %= mo;
      } else {
        (ret *= p2[rc] - 1) %= mo;
      }
    }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
