#include <bits/stdc++.h>
using namespace std;
vector<int> parent(200001);
vector<int> sz(200001);
vector<int> edges(200001);
vector<pair<int, int> > points;
map<int, int> mx;
map<int, int> my;
long long mod = 1000000007;
long long exp(long long x, long long p) {
  if (p == 0) return 1;
  if (p == 1) return x % mod;
  long long temp = exp(x, p / 2);
  temp = (temp * temp) % mod;
  if (p % 2 == 0) return temp;
  temp = (x * temp) % mod;
  return temp;
}
int merge(int x, int y) {
  int r1 = x;
  int r2 = y;
  while (parent[r1] != r1) {
    parent[r1] = parent[parent[r1]];
    r1 = parent[r1];
  }
  while (parent[r2] != r2) {
    parent[r2] = parent[parent[r2]];
    r2 = parent[r2];
  }
  if (r1 == r2) {
    edges[r1]++;
    return 0;
  }
  if (sz[r1] < sz[r2]) {
    parent[r1] = r2;
    sz[r2] += sz[r1];
    edges[r2] += 1 + edges[r1];
  } else {
    parent[r2] = r1;
    sz[r1] += sz[r2];
    edges[r1] += 1 + edges[r2];
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int cx = -1;
  int cy = 1;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    points.push_back(make_pair(a, b));
    if (mx.find(a) == mx.end()) {
      mx[a] = cx;
      cx--;
    }
    if (my.find(b) == my.end()) {
      my[b] = cy;
      cy++;
    }
  }
  int tot = cy - cx - 2;
  for (int i = 1; i <= tot; i++) {
    parent[i] = i;
    sz[i] = 1;
    edges[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int x = points[i].first;
    int y = points[i].second;
    merge(cy - mx[x] - 1, my[y]);
  }
  long long ans = 1;
  for (int i = 1; i <= tot; i++) {
    if (parent[i] != i) continue;
    int x = sz[i];
    int y = edges[i];
    long long temp = exp(2, x);
    if (y == x - 1) temp = (temp + mod - 1) % mod;
    ans = (ans * temp) % mod;
  }
  cout << ans << endl;
}
