#include <bits/stdc++.h>
struct point {
  int x, y;
} p[1000010];
int n;
std::vector<int> xx[1000010], yy[1000010];
int x[1000010], y[1000010], cntx, cnty, vis[1000010];
int posx(int X) { return std::lower_bound(x + 1, x + cntx + 1, X) - x; }
int posy(int Y) { return std::lower_bound(y + 1, y + cnty + 1, Y) - y; }
struct edge {
  int to;
  edge *next;
} * last[1000010], e[2000010], *et = e;
void add(int u, int v) {
  *++et = (edge){v, last[u]}, last[u] = et;
  *++et = (edge){u, last[v]}, last[v] = et;
}
int stackx[1000010], stacky[1000010], topx, topy;
int dfs(int u, int f) {
  vis[u] = 1;
  stackx[++topx] = p[u].x;
  stacky[++topy] = p[u].y;
  int flag = 0;
  for (edge *it = last[u]; it; it = it->next) {
    if (!vis[it->to]) {
      flag |= dfs(it->to, u);
    } else if (it->to != f) {
      flag = 1;
    }
  }
  return flag;
}
const int mod = 1e9 + 7;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &p[i].x, &p[i].y), x[i] = p[i].x, y[i] = p[i].y;
  std::sort(x + 1, x + n + 1);
  std::sort(y + 1, y + n + 1);
  cntx = n, cnty = n;
  cntx = std::unique(x + 1, x + cntx + 1) - x - 1;
  cnty = std::unique(y + 1, y + cnty + 1) - y - 1;
  for (int i = 1; i <= n; i++) {
    p[i].x = posx(p[i].x), p[i].y = posy(p[i].y);
    xx[p[i].x].push_back(i);
    yy[p[i].y].push_back(i);
  }
  for (int i = 1; i <= cntx; i++) {
    for (int j = 0; j < xx[i].size() - 1; j++) add(xx[i][j], xx[i][j + 1]);
  }
  for (int i = 1; i <= cnty; i++) {
    for (int j = 0; j < yy[i].size() - 1; j++) add(yy[i][j], yy[i][j + 1]);
  }
  int ans = 1;
  int t = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      if (!t) t = i;
      topx = topy = 0;
      int v = dfs(i, 0), res = 1;
      std::sort(stackx + 1, stackx + topx + 1);
      std::sort(stacky + 1, stacky + topy + 1);
      topx = std::unique(stackx + 1, stackx + topx + 1) - stackx - 1;
      topy = std::unique(stacky + 1, stacky + topy + 1) - stacky - 1;
      for (int i = 1; i <= topx + topy; i++) res <<= 1, res %= mod;
      res -= v ^ 1;
      ans = 1ll * ans * res % mod;
    }
  }
  printf("%d\n", ans);
}
