#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int N = 200005;
map<int, int> mx, my;
int n, x, y, xx, yy, cnt, ans;
int fa[N], size[N];
bool flag[N];
int father(int x) { return fa[x] == x ? x : fa[x] = father(fa[x]); }
int main() {
  cin >> n;
  for (int i = 1; i <= n * 2; ++i) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> x >> y;
    if (mx.find(x) != mx.end())
      xx = mx[x];
    else
      xx = mx[x] = ++cnt;
    if (my.find(y) != my.end())
      yy = my[y];
    else
      yy = my[y] = ++cnt;
    xx = father(xx);
    yy = father(yy);
    if (xx == yy)
      flag[xx] = 1;
    else {
      if (size[xx] > size[yy]) swap(xx, yy);
      fa[xx] = yy;
      size[yy] += size[xx];
      flag[yy] |= flag[xx];
    }
  }
  ans = 1;
  for (int i = 1; i <= cnt; ++i)
    if (father(i) == i) {
      int temp = 1;
      for (int j = 1; j <= size[i]; ++j) temp = temp * 2 % mo;
      if (!flag[i]) --temp;
      ans = (long long)ans * temp % mo;
    }
  cout << ans << endl;
  return 0;
}
