#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int p = 1e9 + 7;
int read() {
  int s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    write(x / 10), putchar(x % 10 + '0');
}
void print(int x = -1, char c = '\n') {
  write(x);
  putchar(c);
}
int fa[N], xx[N], yy[N], pw[N];
vector<int> a[N];
map<int, vector<int>> x, y;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
signed main(signed Goodbye, char *Wangang[]) {
  (void)Goodbye, (void)Wangang;
  int n = read(), ans = 1;
  for (int i = pw[0] = 1; i <= n + 1; i++) pw[i] = pw[i - 1] * 2 % p;
  for (int i = 1; i <= n; i++) {
    xx[i] = read(), yy[i] = read();
    x[xx[i]].push_back(i);
    y[yy[i]].push_back(i);
    fa[i] = i;
  }
  for (auto i : x)
    for (int j = 0; j + 1 < (int)i.second.size(); j++)
      fa[find(i.second[j])] = find(i.second[j + 1]);
  for (auto i : y)
    for (int j = 0; j + 1 < (int)i.second.size(); j++)
      fa[find(i.second[j])] = find(i.second[j + 1]);
  for (int i = 1; i <= n; i++) a[find(i)].push_back(i);
  for (int i = 1; i <= n; i++)
    if (fa[i] == i) {
      int tot1 = a[i].size();
      set<int> tmp;
      tmp.clear();
      for (int j : a[i]) tmp.insert(xx[j]);
      int tot2 = tmp.size();
      tmp.clear();
      for (int j : a[i]) tmp.insert(yy[j]);
      tot2 += tmp.size();
      ans = 1LL * ans * (pw[tot2] - (tot1 < tot2)) % p;
    }
  print(ans);
  return 0;
}
