#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
map<long long, int> rec;
vector<int> g[222222];
long long a[222222], b[222222];
bool vis[222222];
long long pw2[222222];
int n, m;
inline void add_edge(int x, int y) {
  g[x].push_back(y);
  g[y].push_back(x);
}
pair<int, int> dfs(int v) {
  vis[v] = 1;
  pair<int, int> ret = make_pair(1, 0);
  for (auto u : g[v]) {
    ret.second++;
    if (!vis[u]) {
      pair<int, int> tmp = dfs(u);
      ret.first += tmp.first;
      ret.second += tmp.second;
    }
  }
  return ret;
}
int main() {
  cin >> n;
  vector<int> tmp;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    tmp.push_back(a[i]);
    tmp.push_back(b[i]);
  }
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  for (auto x : tmp) rec[x] = ++m;
  for (int i = 1; i <= n; i++) {
    a[i] = rec[a[i]];
    b[i] = rec[b[i]];
    add_edge(a[i], b[i] + m);
  }
  long long ans = 1;
  pw2[0] = 1;
  m *= 2;
  for (int i = 1; i <= m; i++) pw2[i] = pw2[i - 1] * 2 % mod;
  for (int i = 1; i <= m; i++) {
    if (vis[i]) continue;
    pair<int, int> ret = dfs(i);
    if (ret.first <= ret.second / 2)
      ans = ans * pw2[ret.first];
    else
      ans = ans * (pw2[ret.first] - 1);
    ans = ans % mod;
  }
  ans = (ans % mod + mod) % mod;
  cout << ans << endl;
  return 0;
}
