#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, p = 1e9 + 7;
int n, a[N], b[N], fa[N], fx[N], fy[N];
map<int, int> mx, my;
set<int> sx, sy;
vector<int> g[N];
inline int ask(int x) { return fa[x] == x ? x : fa[x] = ask(fa[x]); }
inline int qmi(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = 1ll * ans * x % p;
    x = 1ll * x * x % p;
    y >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", a + i, b + i), mx[a[i]] = my[b[i]] = 1;
  int id = 0;
  for (map<int, int>::iterator it = mx.begin(); it != mx.end(); ++it)
    it->second = ++id;
  for (int i = 1; i <= n; ++i) {
    int u = mx[a[i]];
    if (fx[u])
      fa[ask(i)] = ask(fx[u]);
    else
      fx[u] = i;
  }
  id = 0;
  for (map<int, int>::iterator it = my.begin(); it != my.end(); ++it)
    it->second = ++id;
  for (int i = 1; i <= n; ++i) {
    int u = my[b[i]];
    if (fy[u])
      fa[ask(i)] = ask(fy[u]);
    else
      fy[u] = i;
  }
  for (int i = 1; i <= n; ++i) g[ask(i)].push_back(i);
  int ans = 1;
  for (int i = 1; i <= n; ++i)
    if (g[i].size()) {
      sx.clear();
      sy.clear();
      for (int j = 0; j < (int)g[i].size(); ++j)
        sx.insert(a[g[i][j]]), sy.insert(b[g[i][j]]);
      int lt = sx.size() + sy.size();
      ans = 1ll * ans * (qmi(2, lt) - (lt > g[i].size())) % p;
    }
  printf("%d", (ans + p) % p);
  return 0;
}
