#include <bits/stdc++.h>
using namespace std;
struct pt {
  int x, y, i;
};
bool cmpx(pt a, pt b) { return a.x < b.x; }
bool cmpy(pt a, pt b) { return a.y < b.y; }
const int mx = 1e5 + 10;
const long long int mod = 1e9 + 7;
int X[mx], Y[mx];
pt p[mx];
long long int pwr[mx + mx];
vector<int> g[mx];
bool vis[mx];
bool cycle;
set<int> xs, ys;
void dfs(int i, int pi) {
  vis[i] = true;
  xs.insert(X[i]);
  ys.insert(Y[i]);
  for (int j : g[i]) {
    if (!vis[j])
      dfs(j, i);
    else if (j != pi)
      cycle = true;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", X + i, Y + i);
    p[i] = {X[i], Y[i], i};
  }
  sort(p, p + n, cmpx);
  for (int i = 1; i < n; i++)
    if (p[i].x == p[i - 1].x) {
      g[p[i].i].push_back(p[i - 1].i);
      g[p[i - 1].i].push_back(p[i].i);
    }
  sort(p, p + n, cmpy);
  for (int i = 1; i < n; i++)
    if (p[i].y == p[i - 1].y) {
      g[p[i].i].push_back(p[i - 1].i);
      g[p[i - 1].i].push_back(p[i].i);
    }
  pwr[0] = 1;
  for (int i = 1; i < mx + mx; i++) pwr[i] = pwr[i - 1] * 2 % mod;
  long long int ans = 1ll;
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      cycle = false;
      xs.clear();
      ys.clear();
      dfs(i, i);
      int s = xs.size() + ys.size();
      if (cycle)
        ans = ans * pwr[s] % mod;
      else
        ans = ans * (pwr[s] - 1 + mod) % mod;
    }
  printf("%lld\n", ans);
  return 0;
}
