#include <bits/stdc++.h>
using namespace std;
char getc() {
  char c = getchar();
  while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
    c = getchar();
  return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int n, ans = 1, p[100010], X[100010], Y[100010], t, u, v;
map<int, int> row, line;
bool flag[100010];
struct data2 {
  int to, nxt;
} edge[100010 << 4];
struct data {
  int i, x, y;
  bool operator<(const data& a) const { return x < a.x; }
} a[100010];
bool cmp1(const data& a, const data& b) { return a.x < b.x; }
void addedge(int x, int y) {
  t++;
  edge[t].to = y, edge[t].nxt = p[x], p[x] = t;
}
int ksm(int a, int k) {
  int s = 1;
  for (; k; k >>= 1, a = 1ll * a * a % 1000000007)
    if (k & 1) s = 1ll * s * a % 1000000007;
  return s;
}
void dfs(int k, int from) {
  flag[k] = 1;
  if (row.find(X[k]) == row.end()) row[X[k]] = 1, u++;
  if (line.find(Y[k]) == line.end()) line[Y[k]] = 1, u++;
  for (int i = p[k]; i; i = edge[i].nxt)
    if (edge[i].to != from)
      if (flag[edge[i].to])
        v = 0;
      else
        dfs(edge[i].to, k);
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    X[i] = a[i].x = read(), Y[i] = a[i].y = read(), a[i].i = i;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int t = i;
    while (t < n && a[t + 1].x == a[i].x) t++;
    for (int j = i; j < t; j++)
      addedge(a[j].i, a[j + 1].i), addedge(a[j + 1].i, a[j].i);
    i = t;
  }
  for (int i = 1; i <= n; i++) swap(a[i].x, a[i].y);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int t = i;
    while (t < n && a[t + 1].x == a[i].x) t++;
    for (int j = i; j < t; j++)
      addedge(a[j].i, a[j + 1].i), addedge(a[j + 1].i, a[j].i);
    i = t;
  }
  for (int i = 1; i <= n; i++)
    if (!flag[i]) {
      row.clear();
      line.clear();
      u = 0;
      v = 1;
      dfs(i, i);
      ans = 1ll * ans * (ksm(2, u) - v) % 1000000007;
    }
  cout << ans;
  return 0;
}
