#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 1e9 + 7;
int n, ind[N], comp_e[N], c, p[N];
pair<int, int> pts[N];
vector<int> adj[N], comp_v[N];
bool mark[N];
int _mul(int a, int b) { return (1LL * a * b) % M; }
void cal_p() {
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = _mul(p[i - 1], 2);
  }
}
bool cmp1(int i, int j) {
  if (pts[i].first != pts[j].first) {
    return (pts[i].first < pts[j].first);
  }
  return (pts[i].second < pts[j].second);
}
bool cmp2(int i, int j) {
  if (pts[i].second != pts[j].second) {
    return (pts[i].second < pts[j].second);
  }
  return (pts[i].first < pts[j].first);
}
void input() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    pts[i] = {x, y};
    ind[i] = i;
  }
}
void add_edges() {
  sort(ind, ind + n, cmp1);
  for (int i = 1; i < n; i++) {
    if (pts[ind[i]].first == pts[ind[i - 1]].first) {
      adj[ind[i]].push_back(ind[i - 1]);
      adj[ind[i - 1]].push_back(ind[i]);
    }
  }
  sort(ind, ind + n, cmp2);
  for (int i = 1; i < n; i++) {
    if (pts[ind[i]].second == pts[ind[i - 1]].second) {
      adj[ind[i]].push_back(ind[i - 1]);
      adj[ind[i - 1]].push_back(ind[i]);
    }
  }
}
void dfs(int u) {
  mark[u] = true;
  comp_v[c].push_back(u);
  comp_e[c] += (int)(adj[u].size());
  for (auto v : adj[u]) {
    if (!mark[v]) {
      dfs(v);
    }
  }
}
void find_comps() {
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      dfs(i);
      c++;
    }
  }
}
void solve() {
  int ans = 1;
  for (int i = 0; i < c; i++) {
    set<int> x, y;
    for (auto point : comp_v[i]) {
      x.insert(pts[point].first);
      y.insert(pts[point].second);
    }
    if ((int)(comp_v[i].size()) <= comp_e[i] / 2) {
      ans = _mul(ans, p[(int)(x.size()) + (int)(y.size())]);
    } else {
      ans = _mul(ans, p[(int)(x.size()) + (int)(y.size())] - 1);
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cal_p();
  input();
  add_edges();
  find_comps();
  solve();
  return 0;
}
