#include <bits/stdc++.h>
using namespace std;
int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const long long POW = 9973;
map<int, vector<int>> mx;
map<int, vector<int>> my;
vector<int> adj[MAXN];
vector<pair<int, int>> inp;
set<int> cx;
set<int> cy;
int flg;
long long p2[MAXN];
map<pair<int, int>, int> coord;
int vis[MAXN];
void dfs(int x, int p) {
  cx.insert(inp[x].first);
  cy.insert(inp[x].second);
  for (int i : adj[x]) {
    if (i != p) {
      if (vis[i])
        flg = 1;
      else {
        vis[i] = 1;
        dfs(i, x);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    mx[x].push_back(y);
    my[y].push_back(x);
    coord[make_pair(x, y)] = i;
    inp.push_back(make_pair(x, y));
  }
  p2[0] = 1;
  for (int i = 1; i <= 2 * n; i++) {
    p2[i] = (p2[i - 1] * 2) % MOD;
  }
  for (auto p : mx) {
    auto v = p.second;
    sort(v.begin(), v.end());
    for (int i = 1; i < v.size(); i++) {
      adj[coord[make_pair(p.first, v[i])]].push_back(
          coord[make_pair(p.first, v[i - 1])]);
      adj[coord[make_pair(p.first, v[i - 1])]].push_back(
          coord[make_pair(p.first, v[i])]);
    }
  }
  for (auto p : my) {
    auto v = p.second;
    sort(v.begin(), v.end());
    for (int i = 1; i < v.size(); i++) {
      adj[coord[make_pair(v[i], p.first)]].push_back(
          coord[make_pair(v[i - 1], p.first)]);
      adj[coord[make_pair(v[i - 1], p.first)]].push_back(
          coord[make_pair(v[i], p.first)]);
    }
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    vis[i] = 1;
    cx.clear();
    cy.clear();
    flg = 0;
    dfs(i, i);
    if (flg)
      ans *= p2[(cx.size() + cy.size())];
    else
      ans *= p2[(cx.size() + cy.size())] - 1;
    ans = (ans % MOD + MOD) % MOD;
  }
  cout << ans;
}
