#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int N = 200005;
map<int, int> mx, my;
int n, x, y, dx, dy, cnt, answer;
int parent[N], Size[N];
bool flag[N];
int get_parent(int x) {
  if (parent[x] == x) {
    return x;
  } else {
    return get_parent(parent[x]);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n; ++i) {
    parent[i] = i;
    Size[i] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> x >> y;
    if (mx.find(x) != mx.end()) {
      dx = mx[x];
    } else {
      dx = mx[x] = ++cnt;
    }
    if (my.find(y) != my.end()) {
      dy = my[y];
    } else {
      dy = my[y] = ++cnt;
    }
    dx = get_parent(dx);
    dy = get_parent(dy);
    if (dx == dy) {
      flag[dx] = 1;
    } else {
      if (Size[dx] > Size[dy]) swap(dx, dy);
      parent[dx] = dy;
      Size[dy] += Size[dx];
      flag[dy] |= flag[dx];
    }
  }
  answer = 1;
  for (int i = 1; i <= cnt; ++i) {
    if (get_parent(i) == i) {
      int temp = 1;
      for (int j = 1; j <= Size[i]; ++j) {
        temp = temp * 2 % mo;
      }
      if (!flag[i]) --temp;
      answer = (long long)answer * temp % mo;
    }
  }
  cout << answer << endl;
  return 0;
}
