#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:250000000")
using namespace std;
const int MOD = (int)1e9 + 7;
const int N = 100000;
int n;
vector<int> G[2 * N + 2];
int x[N], y[N];
map<int, int> idx, idy;
int color[2 * N + 2];
int go(int v, int p, int& c) {
  int res = 1;
  color[v] = 1;
  for (int to : G[v]) {
    if (to != p && color[to] == 1) c = 1;
    if (color[to] == 0) res += go(to, v, c);
  }
  color[v] = 2;
  return res;
}
long long pw[2 * N + 1];
int main() {
  pw[0] = 1;
  for (int i = 1; i <= 2 * N; ++i) {
    pw[i] = pw[i - 1] * 2;
    if (pw[i] >= MOD) pw[i] -= MOD;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    if (!idx.count(x[i])) idx[x[i]] = idx.size();
    if (!idy.count(y[i])) idy[y[i]] = N + idy.size();
    x[i] = idx[x[i]];
    y[i] = idy[y[i]];
    G[x[i]].push_back(y[i]);
    G[y[i]].push_back(x[i]);
  }
  long long res = 1;
  for (int i = 0; i < 2 * N; ++i) {
    if (G[i].empty()) continue;
    int c = 0;
    int sz = go(i, -1, c);
    long long mul = pw[sz];
    if (!c) {
      mul -= 1;
      if (mul < 0) mul += MOD;
    }
    res = res * mul % MOD;
  }
  printf("%I64d\n", res);
  return 0;
}
