#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10, mod = 1e9 + 7;
int n, x[maxn], y[maxn], cycle, num;
vector<int> g[maxn], xx[maxn], yy[maxn];
bool vis[maxn];
map<int, int> xm, ym;
map<int, bool> hasx, hasy;
long long res = 1;
long long po(int a) {
  if (!a) return 1;
  long long t = po(a / 2);
  t *= t;
  t %= mod;
  if (a & 1) t *= 2;
  return t % mod;
}
void dfs(int v, int r) {
  vis[v] = 1;
  if (!hasx[x[v]]) {
    num++;
    hasx[x[v]] = 1;
  }
  if (!hasy[y[v]]) {
    num++;
    hasy[y[v]] = 1;
  }
  for (int u : g[v])
    if (vis[u] && u != r)
      cycle = 1;
    else if (!vis[u])
      dfs(u, v);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int cntx = 0, cnty = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (!xm[x[i]]) xm[x[i]] = ++cntx;
    xx[xm[x[i]]].push_back(i);
    if (!ym[y[i]]) ym[y[i]] = ++cnty;
    yy[ym[y[i]]].push_back(i);
  }
  for (int i = 1; i <= cntx; i++)
    for (int j = 1; j < xx[i].size(); j++)
      g[xx[i][j]].push_back(xx[i][j - 1]), g[xx[i][j - 1]].push_back(xx[i][j]);
  for (int i = 1; i <= cnty; i++)
    for (int j = 1; j < yy[i].size(); j++)
      g[yy[i][j]].push_back(yy[i][j - 1]), g[yy[i][j - 1]].push_back(yy[i][j]);
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      cycle = 0;
      num = 0;
      dfs(i, -1);
      res = 1LL * res * (cycle ? po(num) : po(num) - 1);
      res %= mod;
    }
  cout << res << endl;
  return 0;
}
