#include <bits/stdc++.h>
using namespace std;
vector<int> comp[200001];
int size[200001];
int eds[200001];
int p;
vector<int> adj[200001];
bool v[200001];
int parent[200001];
long long mod = 1000000007LL;
void dfs(int now, int from) {
  v[now] = true;
  parent[now] = from;
  size[p]++;
  comp[p].push_back(now);
  for (int i = 0; i < adj[now].size(); i++) {
    int to = adj[now][i];
    eds[p]++;
    if (!v[to]) {
      dfs(to, now);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> xl;
  vector<int> yl;
  vector<int> ax;
  vector<int> ay;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    xl.push_back(x);
    yl.push_back(y);
    ax.push_back(x);
    ay.push_back(y);
  }
  sort(ax.begin(), ax.end());
  p = 0;
  map<int, int> mx;
  for (int i = 0; i < ax.size(); i++) {
    if (i == 0 || ax[i] != ax[i - 1]) {
      mx[ax[i]] = p++;
    }
  }
  p = 0;
  sort(ay.begin(), ay.end());
  map<int, int> my;
  for (int i = 0; i < ay.size(); i++) {
    if (i == 0 || ay[i] != ay[i - 1]) {
      my[ay[i]] = p++;
    }
  }
  for (int i = 0; i < n; i++) {
    xl[i] = mx[xl[i]];
    yl[i] = my[yl[i]];
    adj[xl[i]].push_back(n + yl[i]);
    adj[n + yl[i]].push_back(xl[i]);
  }
  for (int i = 0; i <= 200000; i++) {
    size[i] = 0;
    eds[i] = 0;
    v[i] = false;
    parent[i] = -1;
  }
  p = 0;
  long long ans = 1LL;
  for (int i = 0; i <= 200000; i++) {
    if (adj[i].size() == 0 || v[i]) {
      continue;
    }
    dfs(i, -1);
    eds[p] /= 2;
    long long now = 1LL;
    if (eds[p] >= size[p]) {
      for (int j = 0; j < size[p]; j++) {
        now *= 2LL;
        now %= mod;
      }
    } else if (size[p] == eds[p] + 1) {
      for (int j = 0; j < size[p]; j++) {
        now *= 2LL;
        now %= mod;
      }
      now--;
      now += mod;
      now %= mod;
    } else {
      assert(false);
    }
    ans *= now;
    ans %= mod;
    p++;
  }
  cout << ans << endl;
  return 0;
}
