#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long modp[200020];
int x[100010];
int y[100010];
vector<int> adj[100010];
int ord[100010];
bool visited[100010];
set<int> xlines, ylines;
int dfs(int v) {
  if (visited[v]) return 0;
  visited[v] = true;
  xlines.insert(x[v]);
  ylines.insert(y[v]);
  int ans = 1;
  for (int u : adj[v]) ans += dfs(u);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) ord[i] = i;
  sort(ord, ord + n, [](int i, int j) {
    return (x[i] < x[j]) || (x[i] == x[j] && y[i] < y[j]);
  });
  for (int i = 1; i < n; i++) {
    int v = ord[i];
    int u = ord[i - 1];
    if (x[v] == x[u]) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  sort(ord, ord + n, [](int i, int j) {
    return (y[i] < y[j]) || (y[i] == y[j] && x[i] < x[j]);
  });
  for (int i = 1; i < n; i++) {
    int v = ord[i];
    int u = ord[i - 1];
    if (y[v] == y[u]) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  modp[0] = 1;
  for (int i = 1; i <= 2 * n; i++) {
    modp[i] = 2 * modp[i - 1] % mod;
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      xlines.clear();
      ylines.clear();
      int q = dfs(i);
      int nlin = xlines.size() + ylines.size();
      long long fat = modp[nlin];
      if (q < nlin) fat = (fat + mod - 1) % mod;
      ans = ans * fat;
      ans %= mod;
    }
  }
  cout << ans << '\n';
  return 0;
}
