#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c, s;
  cin >> n;
  vector<int> a[2], l[2];
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    cin >> c >> s;
    a[c].push_back(s);
    l[c].push_back(i + 1);
  }
  int p, q;
  p = 0;
  q = 0;
  while (p < a[0].size() && q < a[1].size()) {
    if (a[0][p] > a[1][q]) {
      a[0][p] -= a[1][q];
      cout << l[0][p] << ' ' << l[1][q] << ' ' << a[1][q] << endl;
      a[1][q] = 0;
      q++;
    } else {
      a[1][q] -= a[0][p];
      cout << l[0][p] << ' ' << l[1][q] << ' ' << a[0][p] << endl;
      a[0][p] = 0;
      p++;
    }
  }
  p++;
  q++;
  while (p < a[0].size()) {
    cout << l[0][p] << ' ' << l[1][a[1][a[1].size() - 1]] << 0 << endl;
    p++;
  }
  while (q < a[1].size()) {
    cout << l[0][a[0][a[0].size() - 1]] << ' ' << l[1][q] << ' ' << 0 << endl;
    q++;
  }
}
