#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100010];
vector<pair<pair<int, int>, int> > points1, points2;
int visited[100010];
vector<pair<int, int> > orig;
long long ans = 1;
map<int, int> mapx, mapy;
int pts = 0, lines = 0;
void dfs(int s) {
  visited[s] = 1;
  pts++;
  if (!mapx[orig[s].first]) {
    lines++;
    mapx[orig[s].first]++;
  }
  if (!mapy[orig[s].second]) {
    lines++;
    mapy[orig[s].second]++;
  }
  for (int i = 0; i < graph[s].size(); i++) {
    if (!visited[graph[s][i]]) {
      dfs(graph[s][i]);
    }
  }
}
long long raiset(long long x) {
  long long as = 1, a = 2;
  while (x) {
    if (x & 1) as = (as * a) % 1000000007;
    a = (a * a) % 1000000007;
    x /= 2;
  }
  return as;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    orig.push_back(make_pair(a, b));
    points1.push_back(make_pair(make_pair(a, b), i));
    points2.push_back(make_pair(make_pair(b, a), i));
  }
  sort(points1.begin(), points1.end());
  sort(points2.begin(), points2.end());
  map<int, int> xsame, ysame;
  for (int i = 0; i < n; i++) {
    if (ysame.find(points1[i].first.second) != ysame.end()) {
      int a = ysame[points1[i].first.second];
      int b = points1[i].second;
      graph[a].push_back(b);
      graph[b].push_back(a);
      ysame[points1[i].first.second] = b;
    } else {
      ysame[points1[i].first.second] = points1[i].second;
    }
  }
  for (int i = 0; i < n; i++) {
    if (xsame.find(points1[i].first.first) != xsame.end()) {
      int a = xsame[points1[i].first.first];
      int b = points1[i].second;
      graph[a].push_back(b);
      graph[b].push_back(a);
      xsame[points1[i].first.first] = b;
    } else {
      xsame[points1[i].first.first] = points1[i].second;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      lines = 0;
      pts = 0;
      dfs(i);
      if (lines == pts + 1) {
        ans = (ans * ((raiset(lines) - 1) % 1000000007)) % 1000000007;
      } else {
        ans = (ans * raiset(lines)) % 1000000007;
      }
    }
  }
  cout << ans << '\n';
}
