#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 1e5 + 3718;
long long sol = 1, P[N];
int n, a, b, In[N], po, li, cur;
map<int, bool> Dx, Dy;
vector<pair<int, int> > v, g;
vector<int> G[N];
void Dfs(int x) {
  In[x] = 1;
  po++;
  if (!Dx[v[x].first]) {
    Dx[v[x].first] = 1;
    li++;
  }
  if (!Dy[v[x].second]) {
    Dy[v[x].second] = 1;
    li++;
  }
  for (int i = 0; i < G[x].size(); i++) {
    if (!In[G[x][i]]) {
      Dfs(G[x][i]);
    }
  }
}
int main() {
  P[0] = (long long)1;
  for (int i = 1; i < N; i++) {
    P[i] = ((long long)P[i - 1] * 2) % MOD;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  for (int i = 0; i < v.size(); i++) {
    g.push_back(make_pair(v[i].first, i));
  }
  sort(g.begin(), g.end());
  int i = 0;
  while (i != n - 1) {
    cur = g[i].first;
    while (i + 1 != n && cur == g[i + 1].first) {
      G[g[i].second].push_back(g[i + 1].second);
      G[g[i + 1].second].push_back(g[i].second);
      i++;
    }
    if (i != n - 1 && g[i].first != g[i + 1].first) i++;
  }
  g.clear();
  for (int i = 0; i < v.size(); i++) {
    g.push_back(make_pair(v[i].second, i));
  }
  i = 0;
  sort(g.begin(), g.end());
  while (i != n - 1) {
    cur = g[i].first;
    while (i + 1 != n && cur == g[i + 1].first) {
      G[g[i].second].push_back(g[i + 1].second);
      G[g[i + 1].second].push_back(g[i].second);
      i++;
    }
    if (i != n - 1 && g[i].first != g[i + 1].first) i++;
  }
  for (int i = 0; i < n; i++) {
    po = 0, li = 0;
    if (!In[i]) {
      Dfs(i);
      if (po >= li) {
        sol = ((long long)sol * P[li]) % MOD;
      } else {
        long long x = (long long)P[li] - (long long)1;
        sol = ((long long)sol * x) % MOD;
      }
    }
  }
  cout << sol;
  return 0;
}
