#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e+9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> point_idx___x(n);
  vector<int> point_idx___y(n);
  for (int point_idx = 0; point_idx < n; point_idx++) {
    cin >> point_idx___x[point_idx] >> point_idx___y[point_idx];
  }
  map<pair<int, int>, vector<pair<int, int> > > node_id___neigh_id;
  for (int point_idx = 0; point_idx < n; point_idx++) {
    pair<int, int> curr_hor = make_pair(point_idx___x[point_idx], 0);
    pair<int, int> curr_ver = make_pair(point_idx___y[point_idx], 1);
    if (node_id___neigh_id.find(curr_hor) == node_id___neigh_id.end()) {
      node_id___neigh_id[curr_hor] = vector<pair<int, int> >(0);
    }
    if (node_id___neigh_id.find(curr_ver) == node_id___neigh_id.end()) {
      node_id___neigh_id[curr_ver] = vector<pair<int, int> >(0);
    }
    node_id___neigh_id[curr_hor].push_back(curr_ver);
    node_id___neigh_id[curr_ver].push_back(curr_hor);
  }
  int nodes_left = node_id___neigh_id.size();
  map<pair<int, int>, bool> node_id___is_visited;
  for (auto& first_val : node_id___neigh_id) {
    node_id___is_visited[first_val.first] = false;
  }
  long long ans = 1;
  while (nodes_left > 0) {
    pair<int, int> start_node;
    for (auto& node : node_id___is_visited) {
      if (node.second == false) {
        start_node = node.first;
        break;
      }
    }
    node_id___is_visited[start_node] = true;
    stack<pair<pair<int, int>, pair<int, int> > > dfs_stack;
    dfs_stack.push(make_pair(start_node, make_pair(-1, -1)));
    int nodes_count = 1;
    bool cycle_found = false;
    while (!dfs_stack.empty()) {
      pair<int, int> curr_node = dfs_stack.top().first;
      pair<int, int> parent_node = dfs_stack.top().second;
      dfs_stack.pop();
      for (auto& neigh_id : node_id___neigh_id[curr_node]) {
        if (node_id___is_visited[neigh_id]) {
          if (neigh_id != parent_node) {
            cycle_found = true;
          }
          continue;
        }
        dfs_stack.push(make_pair(neigh_id, curr_node));
        node_id___is_visited[neigh_id] = true;
        nodes_count++;
      }
    }
    if (cycle_found) {
      for (int k = 0; k < nodes_count; k++) {
        ans *= 2;
        ans %= MOD;
      }
    } else {
      long long local_ans = 1;
      for (int k = 0; k < nodes_count; k++) {
        local_ans *= 2;
        local_ans %= MOD;
      }
      local_ans += MOD - 1;
      local_ans %= MOD;
      ans *= local_ans;
      ans %= MOD;
    }
    nodes_left -= nodes_count;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
}
