#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000 * 1000 * 1000 + 7;
int n;
pair<int, int> a[112345];
vector<int> v;
vector<pair<int, int> > h[312345], w[312345];
set<int> x, y;
vector<int> g[112345];
bool b[112345];
long long step[312345];
int dfs(int v, int p) {
  b[v] = true;
  int curr = 0;
  x.insert(a[v].first);
  y.insert(a[v].second);
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (!b[to])
      curr = max(curr, dfs(to, v));
    else if (to != p)
      curr = 1;
  }
  return curr;
}
int main() {
  ios_base ::sync_with_stdio(false);
  int i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    v.push_back(a[i].first);
    v.push_back(a[i].second);
  }
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++) {
    a[i].first = lower_bound(v.begin(), v.end(), a[i].first) - v.begin();
    a[i].second = lower_bound(v.begin(), v.end(), a[i].second) - v.begin();
    h[a[i].first].push_back(make_pair(a[i].second, i));
    w[a[i].second].push_back(make_pair(a[i].first, i));
  }
  for (i = 0; i <= 212345; i++) {
    sort(h[i].begin(), h[i].end());
    for (j = 0; j < h[i].size(); j++) {
      if (j < h[i].size() - 1) g[h[i][j].second].push_back(h[i][j + 1].second);
      if (j > 0) g[h[i][j].second].push_back(h[i][j - 1].second);
    }
    sort(w[i].begin(), w[i].end());
    for (j = 0; j < w[i].size(); j++) {
      if (j < w[i].size() - 1) g[w[i][j].second].push_back(w[i][j + 1].second);
      if (j > 0) g[w[i][j].second].push_back(w[i][j - 1].second);
    }
  }
  for (i = 0; i < n; i++) b[i] = false;
  step[0] = 1;
  for (i = 1; i <= 212345; i++) step[i] = (step[i - 1] * 2) % INF;
  long long ans = 1;
  for (i = 0; i < n; i++)
    if (!b[i]) {
      x.clear();
      y.clear();
      int curr = dfs(i, -1);
      long long m = step[x.size() + y.size()] - (curr + 1) % 2;
      ans *= m;
      ans %= INF;
    }
  cout << ans;
  return 0;
}
