#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <unsigned int mod>
class ModInt {
 private:
  unsigned int v;
  static unsigned int norm(const unsigned int& x) {
    return x < mod ? x : x - mod;
  }
  static ModInt make(const unsigned int& x) {
    ModInt m;
    return m.v = x, m;
  }
  static ModInt inv(const ModInt& x) { return make(inverse(x.v, mod)); }
  static unsigned int inverse(int a, int m) {
    int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
    while (*v) {
      t = *u / *v;
      swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]),
          swap(u[2] -= t * v[2], v[2]);
    }
    return (u[1] % m + m) % m;
  }

 public:
  ModInt() : v{0} {}
  ModInt(const long long val) : v{norm(val % mod + mod)} {}
  ModInt(const ModInt<mod>& n) : v{n()} {}
  explicit operator bool() const noexcept { return v != 0; }
  bool operator!() const noexcept { return !static_cast<bool>(*this); }
  ModInt& operator=(const ModInt& n) { return v = n(), (*this); }
  ModInt& operator=(const long long val) {
    return v = norm(val % mod + mod), (*this);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); }
  ModInt operator+(const ModInt& val) const { return make(norm(v + val())); }
  ModInt operator-(const ModInt& val) const {
    return make(norm(v + mod - val()));
  }
  ModInt operator*(const ModInt& val) const {
    return make((long long)v * val() % mod);
  }
  ModInt operator/(const ModInt& val) const { return *this * inv(val); }
  ModInt& operator+=(const ModInt& val) { return *this = *this + val; }
  ModInt& operator-=(const ModInt& val) { return *this = *this - val; }
  ModInt& operator*=(const ModInt& val) { return *this = *this * val; }
  ModInt& operator/=(const ModInt& val) { return *this = *this / val; }
  ModInt operator+(const long long val) const { return ModInt{v + val}; }
  ModInt operator-(const long long val) const { return ModInt{v - val}; }
  ModInt operator*(const long long val) const {
    return ModInt{(long long)v * (val % mod)};
  }
  ModInt operator/(const long long val) const {
    return ModInt{(long long)v * inv(val)};
  }
  ModInt& operator+=(const long long val) { return *this = *this + val; }
  ModInt& operator-=(const long long val) { return *this = *this - val; }
  ModInt& operator*=(const long long val) { return *this = *this * val; }
  ModInt& operator/=(const long long val) { return *this = *this / val; }
  bool operator==(const ModInt& val) const { return v == val.v; }
  bool operator!=(const ModInt& val) const { return !(*this == val); }
  bool operator==(const long long val) const {
    return v == norm(val % mod + mod);
  }
  bool operator!=(const long long val) const { return !(*this == val); }
  unsigned int operator()() const { return v; }
  friend ModInt operator+(const long long val, const ModInt& n) {
    return n + val;
  }
  friend ModInt operator-(const long long val, const ModInt& n) {
    return ModInt{val - n()};
  }
  friend ModInt operator*(const long long val, const ModInt& n) {
    return n * val;
  }
  friend ModInt operator/(const long long val, const ModInt& n) {
    return ModInt{val} / n;
  }
  friend bool operator==(const long long val, const ModInt& n) {
    return n == val;
  }
  friend bool operator!=(const long long val, const ModInt& n) {
    return !(val == n);
  }
  friend istream& operator>>(istream& is, ModInt& n) {
    unsigned int v;
    return is >> v, n = v, is;
  }
  friend ostream& operator<<(ostream& os, const ModInt& n) {
    return (os << n());
  }
  friend ModInt mod_pow(ModInt x, long long n) {
    ModInt ans = 1;
    while (n) {
      if (n & 1) ans *= x;
      x *= x, n >>= 1;
    }
    return ans;
  }
};
using mod = ModInt<1000000007>;
mod inv[200000], fac[200000], finv[200000];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 200000; i++) {
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i);
    fac[i] = fac[i - 1] * i;
    finv[i] = finv[i - 1] * inv[i];
  }
}
mod comb(int a, int b) {
  if (a < b) return 0;
  return fac[a] * finv[b] * finv[a - b];
}
class UnionFind {
 private:
  int sz;
  vector<int> par, size_;

 public:
  UnionFind() {}
  UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1) {
    iota(par.begin(), par.end(), 0);
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (size_[x] < size_[y]) swap(x, y);
    par[y] = x;
    size_[x] += size_[y];
  }
  int size(int x) {
    x = find(x);
    return size_[x];
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, int> > a, b;
  for (int i = 0; i < (int)(n); ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back(make_pair(make_pair(x, y), i));
    b.push_back(make_pair(make_pair(y, x), i));
  }
  UnionFind uf(n);
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  for (int i = 0; i < (int)(n - 1); ++i) {
    if (a[i].first.first == a[i + 1].first.first) {
      uf.unite(a[i].second, a[i + 1].second);
    }
    if (b[i].first.first == b[i + 1].first.first) {
      uf.unite(b[i].second, b[i + 1].second);
    }
  }
  map<int, set<int> > mpx, mpy;
  for (int i = 0; i < (int)(n); ++i) {
    mpx[uf.find(a[i].second)].insert(a[i].first.first);
    mpy[uf.find(a[i].second)].insert(a[i].first.second);
  }
  mod res = 1;
  for (auto& x : mpx) {
    int k = x.first;
    int line = 0;
    line += x.second.size();
    line += mpy[k].size();
    int sz = uf.size(k);
    if (sz >= line) {
      res *= mod_pow((mod)2, line);
    } else {
      res *= mod_pow((mod)2, line) - 1;
    }
  }
  cout << res << endl;
  return 0;
}
