#include <bits/stdc++.h>
using namespace std;
void read(long long &x) { scanf("%lld", &x); }
void read(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void read(long long &x, long long &y, long long &z) {
  scanf("%lld%lld%lld", &x, &y, &z);
}
void print(long long x) { printf("%lld ", x); }
void println(long long x) { printf("%lld\n", x); }
const long long N = 1000000;
long long n, ans = 1, ch, x, y, w[N + 10];
pair<long long, long long> a[N + 10];
vector<long long> v[N + 10];
map<long long, long long> xx, yy;
void dfs(long long x, long long pr) {
  w[x] = 1;
  xx[a[x].first] = 1;
  yy[a[x].second] = 1;
  for (long long to : v[x]) {
    if (!w[to])
      dfs(to, x);
    else if (w[to] == 1 && to != pr)
      ch = 0;
  }
  w[x] = 2;
}
long long bin(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) (ans *= a) %= 1000000007;
    (a *= a) %= 1000000007;
    n /= 2;
  }
  return ans;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) read(a[i].first, a[i].second);
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= n; i++) {
    x = xx[a[i].first];
    y = yy[a[i].second];
    if (x) v[x].push_back(i), v[i].push_back(x);
    if (y) v[y].push_back(i), v[i].push_back(y);
    xx[a[i].first] = i;
    yy[a[i].second] = i;
  }
  for (long long i = 1; i <= n; i++)
    if (!w[i]) {
      xx.clear();
      yy.clear();
      ch = 1;
      dfs(i, 0);
      ans *= bin(2, xx.size() + yy.size()) - ch;
      ans %= 1000000007;
    }
  cout << ans;
}
