#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 19;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-8;
map<long long, int> Mx;
int ch(long long x) {
  if (Mx.count(x)) return Mx[x];
  int t = Mx.size() + 1;
  return Mx[x] = t;
}
vector<pair<int, int> > Ve;
int r[200050];
int root(int x) { return (x == r[x]) ? x : (r[x] = root(r[x])); }
int vcnt[200050];
int ecnt[200050];
long long po2[200050];
int main() {
  int N, i;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    long long t1, t2;
    scanf("%lld %lld", &t1, &t2);
    t2 += LL_INF;
    t1 = ch(t1), t2 = ch(t2);
    Ve.emplace_back(t1, t2);
  }
  int X = Mx.size();
  for (i = 1; i <= X; i++) r[i] = i;
  for (auto it : Ve) r[root(it.first)] = root(it.second);
  for (i = 1; i <= X; i++) vcnt[root(i)]++;
  for (auto it : Ve) ecnt[root(it.first)]++;
  long long ans = 1;
  po2[0] = 1;
  for (i = 1; i <= 200000; i++) po2[i] = po2[i - 1] * 2 % MOD;
  for (i = 1; i <= X; i++) {
    if (ecnt[i] == 0) continue;
    long long v = po2[vcnt[i]];
    if (vcnt[i] - 1 == ecnt[i]) v--;
    ans = (ans * v) % MOD;
  }
  return !printf("%lld\n", ans);
}
