#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int pw2[maxn], x[maxn], y[maxn], a[maxn], b[maxn], line_cnt, point_cnt;
vector<pair<int, int> > vec1[maxn], vec2[maxn];
bool used1[maxn], used2[maxn], used3[maxn];
int pow_mod(int x, int n) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    n >>= 1;
  }
  return ret;
}
void dfs(int x, int c) {
  ++line_cnt;
  if (c == 1) {
    used1[x] = true;
    for (auto y : vec1[x]) {
      if (!used3[y.second]) {
        ++point_cnt;
        used3[y.second] = true;
      }
      if (!used2[y.first]) dfs(y.first, 2);
    }
  } else {
    used2[x] = true;
    for (auto y : vec2[x]) {
      if (!used3[y.second]) {
        ++point_cnt;
        used3[y.second] = true;
      }
      if (!used1[y.first]) dfs(y.first, 1);
    }
  }
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i < maxn; ++i) pw2[i] = (2LL * pw2[i - 1]) % mod;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    a[i] = x[i], b[i] = y[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  int m1 = unique(a + 1, a + n + 1) - a - 1;
  int m2 = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; ++i) {
    int xx = lower_bound(a + 1, a + m1 + 1, x[i]) - a;
    int yy = lower_bound(b + 1, b + m2 + 1, y[i]) - b;
    vec1[xx].push_back(pair<int, int>(yy, i));
    vec2[yy].push_back(pair<int, int>(xx, i));
  }
  int ans = 1;
  for (int i = 1; i <= m1; ++i) {
    if (used1[i]) continue;
    line_cnt = point_cnt = 0;
    dfs(i, 1);
    if (line_cnt > point_cnt)
      ans = (long long)ans * (pw2[line_cnt] - 1) % mod;
    else
      ans = (long long)ans * pw2[line_cnt] % mod;
  }
  printf("%d\n", ans);
  return 0;
}
