#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
int pow_mod(int a, int n) {
  long long res = 1, t = a;
  while (n) {
    if (n & 1) res = res * t % mod;
    t = t * t % mod;
    n /= 2;
  }
  return res;
}
long long fac[MAXN * 2];
int C(int n, int m) {
  if (n == m) return 1;
  if (m == 0) return 1;
  if (n < m) return 0;
  long long res = fac[n];
  res = res * pow_mod(fac[m], mod - 2) % mod;
  res = res * pow_mod(fac[n - m], mod - 2) % mod;
  return res;
}
int n;
struct node {
  int id;
  int x, y;
} a[MAXN];
bool cmp1(node a, node b) { return a.x < b.x; }
bool cmp2(node a, node b) { return a.y < b.y; }
vector<int> v;
int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }
int f[MAXN];
int ve[MAXN];
int num[MAXN];
void init(int n) {
  for (int i = 1; i <= n; i++) f[i] = i, ve[i] = 1, num[i] = 2;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  num[fx]--;
  if (fx == fy) return;
  num[fx] += num[fy];
  ve[fx] += ve[fy];
  f[fy] = fx;
}
int solve(int x) {
  long long res = pow_mod(2, num[x]);
  for (int i = ve[x] + 1; i <= num[x]; i++) {
    res = res - C(num[x], i);
    if (res < 0) res += mod;
  }
  return res;
}
int vis[MAXN];
int main() {
  fac[0] = 1;
  for (int i = 1; i < MAXN * 2; i++) fac[i] = fac[i - 1] * i % mod;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    v.push_back(a[i].x);
    v.push_back(a[i].y);
    a[i].id = i;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; i++) {
    a[i].x = getid(a[i].x);
    a[i].y = getid(a[i].y);
  }
  init(n);
  sort(a + 1, a + 1 + n, cmp1);
  for (int i = 2; i <= n; i++) {
    if (a[i].x == a[i - 1].x) merge(a[i].id, a[i - 1].id);
  }
  sort(a + 1, a + 1 + n, cmp2);
  for (int i = 2; i <= n; i++) {
    if (a[i].y == a[i - 1].y) merge(a[i].id, a[i - 1].id);
  }
  long long res = 1;
  for (int i = 1; i <= n; i++) {
    if (!vis[find(i)]) {
      vis[find(i)] = 1;
      res = res * solve(find(i)) % mod;
    }
  }
  printf("%lld\n", res);
  return 0;
}
