#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
vector<int> e[100010];
struct cc {
  int x, y, id;
} a[100010];
int n, m, i, j, cx, cy = 100002, x, y;
bool vis[100010];
map<int, int> lx, ly;
bool cmx(cc x, cc y) {
  if (x.x == y.x) return x.y < y.y;
  return x.x < y.x;
}
bool cmy(cc x, cc y) {
  if (x.y == y.y) return x.x < y.x;
  return x.y < y.y;
}
bool cmi(cc x, cc y) { return x.id < y.id; }
set<int> sx, sy;
long long mod = 1e9 + 7, ans = 1;
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  long long z = qp(x, y / 2);
  z = z * z % mod;
  if (y & 1) z = z * x % mod;
  return z;
}
bool dfs(int x, int fa) {
  bool dg = 0;
  vis[x] = 1;
  int i;
  sx.insert(a[x].x);
  sx.insert(a[x].y);
  for (i = 0; i < e[x].size(); i++) {
    if (e[x][i] == fa) continue;
    if (vis[e[x][i]])
      dg = 1;
    else
      dg |= dfs(e[x][i], x);
  }
  return dg;
}
int main() {
  readi(n);
  for (i = 1; i <= n; i++) {
    readi(x);
    readi(y);
    if (!lx.count(x)) lx[x] = ++cx;
    a[i].x = lx[x];
    if (!ly.count(y)) ly[y] = ++cy;
    a[i].y = ly[y];
    a[i].id = i;
  }
  stable_sort(a + 1, a + n + 1, cmx);
  for (i = 1; i < n; i++) {
    if (a[i].x == a[i + 1].x) {
      e[a[i].id].push_back(a[i + 1].id);
      e[a[i + 1].id].push_back(a[i].id);
    }
  }
  stable_sort(a + 1, a + n + 1, cmy);
  for (i = 1; i < n; i++) {
    if (a[i].y == a[i + 1].y) {
      e[a[i].id].push_back(a[i + 1].id);
      e[a[i + 1].id].push_back(a[i].id);
    }
  }
  stable_sort(a + 1, a + n + 1, cmi);
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    sx.clear();
    sy.clear();
    if (dfs(i, 0)) {
      ans *= qp(2, sx.size() + sy.size());
    } else
      ans *= qp(2, sx.size() + sy.size()) - 1;
    ans %= mod;
  }
  cout << ans;
  return 0;
}
