#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<long long> dx = {1, -1, 0, 0};
vector<long long> dy = {0, 0, 1, -1};
vector<vector<long long>> g;
vector<long long> elem;
vector<long long> rrank;
void init(long long num) {
  elem = vector<long long>(num, 0);
  rrank = vector<long long>(num, 0);
  for (int i = 0; i < num; ++i) {
    elem[i] = i;
  }
}
long long dfs(long long num) {
  if (elem[num] == num) {
    return num;
  } else {
    elem[num] = dfs(elem[num]);
    return elem[num];
  }
}
void unite(long long a, long long b) {
  a = dfs(a);
  b = dfs(b);
  if (a == b) {
    return;
  } else {
    if (rrank[a] < rrank[b]) {
      elem[a] = b;
    } else {
      if (rrank[a] == rrank[b]) {
        rrank[a]++;
      }
      elem[b] = a;
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  init(n);
  vector<pair<long long, long long>> v(n);
  for (int i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    v[i] = pair<long long, long long>(a, b);
  }
  for (int i = 0; i < n; ++i) {
    if (elem[i] != i) {
      continue;
    }
    for (int j = i + 1; j < n; ++j) {
      if (elem[j] == j) {
        if (v[i].first * v[j].second + v[i].second - v[j].first == 0 ||
            v[i] == v[j]) {
          unite(i, j);
          dfs(j);
        }
      }
    }
  }
  map<long long, map<pair<long long, long long>, long long>> c;
  for (int i = 0; i < v.size(); ++i) {
    c[elem[i]][v[i]]++;
  }
  vector<long long> cc(n + 1);
  cc[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cc[i] = 2ll * cc[i - 1] + 1ll;
    cc[i] %= mod;
  }
  long long ret = 1ll;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    auto cur = itr->second;
    long long tmp = 1;
    for (auto iitr = cur.begin(); iitr != cur.end(); ++iitr) {
      tmp += cc[iitr->second - 1ll];
      tmp %= mod;
    }
    ret *= tmp;
    ret %= mod;
  }
  ret -= 1ll;
  ret %= mod;
  cout << ret << endl;
  return 0;
}
