#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
int x[100035], y[100035];
map<int, vector<int>> xl, yl;
vector<int> mp[100035];
bool vis[100035], cyl;
set<int> sx, sy;
void addE(int u, int v) {
  mp[u].push_back(v);
  mp[v].push_back(u);
}
void dfs(int u, int pa) {
  vis[u] = 1;
  sx.insert(x[u]);
  sy.insert(y[u]);
  for (int c : mp[u])
    if (c != pa) {
      if (vis[c])
        cyl = 1;
      else
        dfs(c, u);
    }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d%d", x + i, y + i);
    xl[x[i]].push_back(i);
    yl[y[i]].push_back(i);
  }
  for (auto &p : xl) {
    sort(p.second.begin(), p.second.end());
    for (int i = 1; i < p.second.size(); i++) {
      int u = p.second[i - 1], v = p.second[i];
      addE(u, v);
    }
  }
  for (auto &p : yl) {
    sort(p.second.begin(), p.second.end());
    for (int i = 1; i < p.second.size(); i++) {
      int u = p.second[i - 1], v = p.second[i];
      addE(u, v);
    }
  }
  long long ans = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (!vis[i]) {
      cyl = 0;
      sx.clear();
      sy.clear();
      dfs(i, 0);
      int N = sx.size() + sy.size();
      int tmp = fastPow(2, N);
      if (!cyl) addmod(tmp, 1000000007 - 1);
      ans = ans * tmp % 1000000007;
    }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
