#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <const int &MOD>
struct _m_int {
  int val;
  _m_int(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = int(v);
  }
  _m_int(uint64_t v) {
    if (v >= MOD) v %= MOD;
    val = int(v);
  }
  _m_int(int v) : _m_int(int64_t(v)) {}
  _m_int(unsigned v) : _m_int(uint64_t(v)) {}
  static int inv_mod(int a, int m = MOD) {
    int g = m, r = a, x = 0, y = 1;
    while (r != 0) {
      int q = g / r;
      g %= r;
      swap(g, r);
      x -= q * y;
      swap(x, y);
    }
    return x < 0 ? x + m : x;
  }
  explicit operator int() const { return val; }
  explicit operator unsigned() const { return val; }
  explicit operator int64_t() const { return val; }
  explicit operator uint64_t() const { return val; }
  explicit operator double() const { return val; }
  explicit operator long double() const { return val; }
  _m_int &operator+=(const _m_int &other) {
    val -= MOD - other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  _m_int &operator-=(const _m_int &other) {
    val -= other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return unsigned(x % m);
    unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  _m_int &operator*=(const _m_int &other) {
    val = fast_mod(uint64_t(val) * other.val);
    return *this;
  }
  _m_int &operator/=(const _m_int &other) { return *this *= other.inv(); }
  friend _m_int operator+(const _m_int &a, const _m_int &b) {
    return _m_int(a) += b;
  }
  friend _m_int operator-(const _m_int &a, const _m_int &b) {
    return _m_int(a) -= b;
  }
  friend _m_int operator*(const _m_int &a, const _m_int &b) {
    return _m_int(a) *= b;
  }
  friend _m_int operator/(const _m_int &a, const _m_int &b) {
    return _m_int(a) /= b;
  }
  _m_int &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  _m_int &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  _m_int operator++(int) {
    _m_int before = *this;
    ++*this;
    return before;
  }
  _m_int operator--(int) {
    _m_int before = *this;
    --*this;
    return before;
  }
  _m_int operator-() const { return val == 0 ? 0 : MOD - val; }
  friend bool operator==(const _m_int &a, const _m_int &b) {
    return a.val == b.val;
  }
  friend bool operator!=(const _m_int &a, const _m_int &b) {
    return a.val != b.val;
  }
  friend bool operator<(const _m_int &a, const _m_int &b) {
    return a.val < b.val;
  }
  friend bool operator>(const _m_int &a, const _m_int &b) {
    return a.val > b.val;
  }
  friend bool operator<=(const _m_int &a, const _m_int &b) {
    return a.val <= b.val;
  }
  friend bool operator>=(const _m_int &a, const _m_int &b) {
    return a.val >= b.val;
  }
  _m_int inv() const { return inv_mod(val); }
  _m_int pow(int64_t p) const {
    if (p < 0) return inv().pow(-p);
    _m_int a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      p >>= 1;
      if (p > 0) a *= a;
    }
    return result;
  }
  friend ostream &operator<<(ostream &os, const _m_int &m) {
    return os << m.val;
  }
};
const int MOD = 1e9 + 7;
using mod_int = _m_int<MOD>;
vector<mod_int> fact, invfact, inv;
void prepare_factorials(int N) {
  assert(N >= 2);
  fact.resize(N + 1);
  invfact.resize(N + 1);
  inv.resize(N + 1);
  inv[1] = invfact[1] = invfact[0] = fact[0] = fact[1] = 1;
  for (int i = 2; i <= N; i++) {
    fact[i] = fact[i - 1] * i;
    inv[i] = inv[MOD % i] * (MOD - MOD / i);
    invfact[i] = invfact[i - 1] * inv[i];
  }
}
mod_int choose(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fact[n] * (invfact[k] * invfact[n - k]);
}
int e = 0, v = 0;
void dfs(int s, int p, vector<int> &vis, vector<vector<int>> &g) {
  assert(s < g.size() && s < vis.size());
  vis[s] = true;
  v++;
  for (auto u : g[s]) {
    if (u == p) continue;
    e++;
    if (vis[u]) continue;
    dfs(u, s, vis, g);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  prepare_factorials(n + 12);
  vector<int> x(n), y(n);
  int cnt = 0;
  map<int, int> xm, ym;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (!xm.count(x[i])) {
      xm[x[i]] = cnt++;
    }
    if (!ym.count(y[i])) {
      ym[y[i]] = cnt++;
    }
  }
  vector<vector<int>> g(cnt);
  vector<int> vis(cnt);
  mod_int ans = 1;
  for (int i = 0; i < n; i++) {
    g[xm[x[i]]].push_back(ym[y[i]]);
    g[ym[y[i]]].push_back(xm[x[i]]);
  }
  for (int i = 0; i < cnt; i++) {
    if (!vis[i]) {
      e = 0;
      v = 0;
      dfs(i, -1, vis, g);
      mod_int prod = 0;
      if (e == v - 1) {
        prod = mod_int(2).pow(v) - 1;
      } else {
        prod = mod_int(2).pow(v);
      }
      ans *= prod;
    }
  }
  cout << ans << '\n';
}
