#include <bits/stdc++.h>
using namespace std;
long long lmin(long long a, long long b) { return (a < b) ? a : b; }
long long lmax(long long a, long long b) { return (a > b) ? a : b; }
long double dmin(long double a, long double b) { return (a < b) ? a : b; }
long double dmax(long double a, long double b) { return (a > b) ? a : b; }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return res;
}
long long lpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
long double dpow(long double a, long long n) {
  long double res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
set<pair<int, int> > ans;
set<pair<int, int> >::iterator it;
vector<vector<int> > v;
vector<int> v1;
int main() {
  int n, x, y, val;
  cin >> n;
  vector<bool> use(n, true);
  vector<int> xr(n, 0);
  vector<int> deg(n, 0);
  for (int i = 0; i < n; i++) v.push_back(v1);
  v1.clear();
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == 0)
      use[i] = false;
    else if (x == 1) {
      if (i < y)
        ans.insert(make_pair(i, y));
      else
        ans.insert(make_pair(y, i));
      v[i].push_back(y);
      deg[y]--;
      v[y].push_back(i);
      use[i] = false;
    } else {
      deg[i] += x;
      xr[i] = y;
    }
  }
  for (int i = 0; i < n; i++) {
    if (use[i] && deg[i] == 1) v1.push_back(i);
    if (deg[i] == 0) use[i] = false;
  }
  while (v1.size()) {
    x = v1[0];
    v1.erase(v1.begin());
    if (deg[x] != 1) continue;
    val = xr[x];
    deg[x] = 0;
    for (int i = 0; i < v[x].size(); i++) val = (val ^ v[x][i]);
    deg[val]--;
    if (val < x)
      ans.insert(make_pair(val, x));
    else
      ans.insert(make_pair(x, val));
    v[val].push_back(x);
    v[x].push_back(val);
    if (deg[val] == 1) v1.push_back(val);
    if (deg[val] == 0) use[val] = false;
  }
  cout << ans.size() << endl;
  for (it = ans.begin(); it != ans.end(); it++)
    cout << (*it).first << " " << (*it).second << endl;
  return 0;
}
