#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct data {
  int x, y, id;
} a[N];
inline bool cmpx(data a, data b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
inline bool cmpy(data a, data b) {
  if (a.y == b.y) return a.x < b.x;
  return a.y < b.y;
}
int ycl[N << 1], cycle[N], n, father[N], ans = 1, mod = 1000000007, sum[N];
set<int> sx[N], sy[N];
inline int getfather(int x) {
  return father[x] == x ? x : father[x] = getfather(father[x]);
}
inline void uni(int x, int y) {
  int t1 = getfather(x), t2 = getfather(y);
  if (t1 != t2) {
    father[t1] = t2;
    cycle[t2] |= cycle[t1];
  } else
    cycle[t1] = 1;
}
int main() {
  scanf("%d", &n);
  ycl[0] = 1;
  for (int i = 1; i <= n; i++) {
    father[i] = a[i].id = i;
    ycl[i] = ycl[i - 1] * 2 % mod;
    scanf("%d%d", &a[i].x, &a[i].y);
  }
  for (int i = n + 1; i <= 2 * n; i++) ycl[i] = ycl[i - 1] * 2 % mod;
  sort(&a[1], &a[n + 1], cmpx);
  for (int i = 1; i < n; i++)
    if (a[i + 1].x == a[i].x) uni(a[i].id, a[i + 1].id);
  sort(&a[1], &a[n + 1], cmpy);
  for (int i = 1; i < n; i++)
    if (a[i + 1].y == a[i].y) uni(a[i].id, a[i + 1].id);
  for (int i = 1; i <= n; i++) {
    sx[getfather(a[i].id)].insert(a[i].x);
    sy[father[a[i].id]].insert(a[i].y);
  }
  for (int i = 1; i <= n; i++)
    if (getfather(i) == i) {
      ans = (long long)ans * (ycl[sx[i].size() + sy[i].size()] + cycle[i] - 1) %
            mod;
    }
  cout << ans << endl;
}
