#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int maxn = 100010;
int n, pow2[maxn];
map<int, vector<int>> adj;
map<int, int> deg;
set<int> vis;
int sumv, sumdeg;
void dfs(int x) {
  sumv++;
  sumdeg += deg[x];
  vis.insert(x);
  for (auto y : adj[x])
    if (vis.count(y) == 0) dfs(y);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  pow2[0] = 1;
  for (int i = 0; i < maxn - 1; ++i) pow2[i + 1] = (pow2[i] << 1) % M;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    x = x << 1;
    y = y << 1 ^ 1;
    adj[x].emplace_back(y), adj[y].emplace_back(x);
    deg[x]++, deg[y]++;
  }
  int ans = 1;
  for (auto [x, r] : adj) {
    if (vis.count(x) == 0) {
      sumv = 0, sumdeg = 0;
      dfs(x);
      int a = pow2[sumv];
      if (sumdeg == sumv * 2 - 2) --a;
      ans = 1LL * ans * a % M;
    }
  }
  cout << ans << '\n';
}
