#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N];
int y[N];
int sort_by_x[N];
int sort_by_y[N];
int p[N];
int r[N];
int e[N];
set<int> xs[N];
set<int> ys[N];
void init(int n) {
  for (int i = 0; i <= n; i++) {
    p[i] = i;
    r[i] = 1;
  }
}
int Find(int i) {
  if (p[i] == i) return i;
  return p[i] = Find(p[i]);
}
void Union(int i, int j) {
  i = Find(i), j = Find(j);
  if (r[i] < r[j]) swap(i, j);
  p[j] = i;
  r[i] += r[j];
}
const int MOD = 1e9 + 7;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}
int mul(int a, int b) { return (long long)a * b % MOD; }
int power(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", x + i, y + i);
    sort_by_x[i] = sort_by_y[i] = i;
  }
  sort(sort_by_x + 1, sort_by_x + 1 + n, [&](int u, int v) {
    if (x[u] == x[v]) return y[u] < y[v];
    return x[u] < x[v];
  });
  sort(sort_by_y + 1, sort_by_y + 1 + n, [&](int u, int v) {
    if (y[u] == y[v]) return x[u] < x[v];
    return y[u] < y[v];
  });
  init(n);
  for (int i = 2; i <= n; i++) {
    if (x[sort_by_x[i]] == x[sort_by_x[i - 1]]) {
      Union(sort_by_x[i], sort_by_x[i - 1]);
    }
    if (y[sort_by_y[i]] == y[sort_by_y[i - 1]]) {
      Union(sort_by_y[i], sort_by_y[i - 1]);
    }
  }
  for (int i = 2; i <= n; i++) {
    if (x[sort_by_x[i]] == x[sort_by_x[i - 1]]) {
      e[Find(sort_by_x[i])]++;
    }
    if (y[sort_by_y[i]] == y[sort_by_y[i - 1]]) {
      e[Find(sort_by_y[i])]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    xs[Find(i)].insert(x[i]);
    ys[Find(i)].insert(y[i]);
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (Find(i) == i) {
      if (r[i] == e[i] + 1) {
        ans = mul(ans, add(mul(power(2, xs[i].size()), power(2, ys[i].size())),
                           MOD - 1));
      } else {
        ans = mul(ans, mul(power(2, xs[i].size()), power(2, ys[i].size())));
      }
    }
  }
  cout << ans << endl;
}
