#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
const long long mol = 1e9 + 7;
int fa[maxn + 11], siz[maxn + 11], x[maxn + 11], y[maxn + 11];
bool cir[maxn + 11];
vector<int> row, cul;
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
void merge(int x, int y) {
  int fax = get(x);
  int fay = get(y);
  if (fax == fay) {
    cir[fax] = true;
    return;
  }
  fa[fay] = fax;
  cir[fax] |= cir[fay];
  siz[fax] += siz[fay];
}
long long qpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mol;
    a = a * a % mol;
    b >>= 1;
  }
  return ans;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mol;
  return a;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    row.emplace_back(x[i]);
    cul.emplace_back(y[i]);
  }
  sort((row).begin(), (row).end());
  row.erase(unique((row).begin(), (row).end()), row.end());
  sort((cul).begin(), (cul).end());
  cul.erase(unique((cul).begin(), (cul).end()), cul.end());
  int m = row.size() + cul.size();
  for (int i = 1; i <= m; i++) fa[i] = i, siz[i] = 1, cir[i] = false;
  for (int i = 1; i <= n; i++) {
    x[i] = lower_bound((row).begin(), (row).end(), x[i]) - row.begin() + 1;
    y[i] = lower_bound((cul).begin(), (cul).end(), y[i]) - cul.begin() +
           row.size() + 1;
    merge(x[i], y[i]);
  }
  long long ans = 1;
  for (int i = 1; i <= m; i++)
    if (get(i) == i) {
      int p = siz[i];
      long long t = qpow(2, p);
      if (!cir[i]) t = sub(t, 1);
      ans = ans * t % mol;
    }
  printf("%lld\n", ans);
}
