You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.

You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109 + 7.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of points.

n lines follow. The (i + 1)-th of these lines contains two integers xi, yi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the i-th point.

It is guaranteed that all points are distinct.

Output

Print the number of possible distinct pictures modulo 109 + 7.

Examples

Input

4
1 1
1 2
2 1
2 2


Output

16


Input

2
-1 -1
0 1


Output

9

Note

In the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it).

The first way: <image> The second way: <image>

In the second example you can work with two points independently. The number of pictures is 32 = 9.
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printRange(T &x) {
  for (auto y : x) cout << y << ' ';
  cout << endl;
}
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug &operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5 + 10;
int n;
vector<int> x, y;
vector<pair<int, int> > pts;
vector<int> g[(maxn << 1) + 10];
bool vis[(maxn << 1) + 10];
template <typename c>
void mod(c &x) {
  x = (x + 1000000007) % 1000000007;
}
int sz = 0;
bool dfs(int x, int par = -1) {
  bool ans = false;
  vis[x] = true;
  sz++;
  for (auto y : g[x]) {
    if (y == par) continue;
    ans |= vis[y];
    if (!vis[y]) ans |= dfs(y, x);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<long long> p2(maxn);
  p2[0] = 1;
  for (int i = (1); i < (maxn); ++i) {
    p2[i] = p2[i - 1] << 1;
    mod(p2[i]);
  }
  cin >> n;
  x.resize(n), y.resize(n);
  for (int i = (0); i < (n); ++i) {
    cin >> x[i] >> y[i];
    pts.emplace_back(x[i], y[i]);
  }
  x.resize(unique(x.begin(), x.end()) - x.begin());
  y.resize(unique(y.begin(), y.end()) - y.begin());
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  auto wherex = [&](int xx) {
    int ret = lower_bound(x.begin(), x.end(), xx) - x.begin();
    return ret;
  };
  auto wherey = [&](int yy) {
    int ret = lower_bound(y.begin(), y.end(), yy) - y.begin();
    return ret + x.size();
  };
  for (auto pt : pts) {
    int xx = wherex(pt.first);
    int yy = wherey(pt.second);
    g[xx].push_back(yy);
    g[yy].push_back(xx);
  }
  long long ans = 1;
  for (int l = 0; l < (maxn << 1) + 10; l++) {
    if (vis[l]) continue;
    sz = 0;
    if (dfs(l)) {
      ans *= p2[sz];
      mod(ans);
    } else {
      ans *= p2[sz] - 1;
      mod(ans);
    }
  }
  cout << ans << endl;
  return 0;
}
