#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char ch = getchar(), w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * w;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
using namespace std;
const int N = 1e5 + 666;
int c[N * 2], d[N];
struct T {
  int x, y;
} a[N];
int n;
vector<pair<int, int> > x[N], y[N];
int cnt;
long long sum;
set<int> dx, dy;
vector<int> g[N];
bool vis[N];
void dfs(int x) {
  sum += g[x].size();
  vis[x] = 1;
  ++cnt;
  dx.insert(a[x].x);
  dy.insert(a[x].y);
  for (int y : g[x])
    if (!vis[y]) dfs(y);
}
const long long mo = 1e9 + 7;
long long ksm(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % mo)
    if (y & 1) res = res * x % mo;
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i].x = read();
    a[i].y = read();
    c[++*c] = a[i].x;
    d[++*d] = a[i].y;
  }
  sort(c + 1, c + 1 + *c);
  sort(d + 1, d + 1 + *d);
  *c = unique(c + 1, c + 1 + *c) - c - 1;
  *d = unique(d + 1, d + 1 + *d) - d - 1;
  for (int i = 1; i <= n; ++i) {
    a[i].x = lower_bound(c + 1, c + 1 + *c, a[i].x) - c;
    a[i].y = lower_bound(d + 1, d + 1 + *d, a[i].y) - d;
  }
  for (int i = 1; i <= n; ++i) {
    x[a[i].x].push_back(make_pair(a[i].y, i));
    y[a[i].y].push_back(make_pair(a[i].x, i));
  }
  for (int i = 1; i <= *c; ++i) {
    sort(x[i].begin(), x[i].end());
    for (int j = 1; j < x[i].size(); ++j) {
      int t1 = x[i][j - 1].second;
      int t2 = x[i][j].second;
      g[t1].push_back(t2);
      g[t2].push_back(t1);
    }
  }
  for (int i = 1; i <= *d; ++i) {
    sort(y[i].begin(), y[i].end());
    for (int j = 1; j < y[i].size(); ++j) {
      int t1 = y[i][j - 1].second;
      int t2 = y[i][j].second;
      g[t1].push_back(t2);
      g[t2].push_back(t1);
    }
  }
  long long ans = 1;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      dfs(i);
      long long k = ksm(2, dx.size() + dy.size());
      if (sum / 2 == cnt - 1) --k;
      ans = ans * k % mo;
      cnt = 0;
      sum = 0;
      dx.clear();
      dy.clear();
    }
  writeln(ans);
  return 0;
}
