#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, c, x, y, N;
  queue<pair<long long int, long long int> > q[4];
  bool flag;
  cin >> N;
  for (i = 1; i <= N; i++) {
    cin >> j >> k;
    q[j].push(make_pair(i, k));
  }
  c = 1, x = q[1].front().first, y = q[1].front().second;
  q[1].pop();
  while (!q[0].empty() || !q[1].empty()) {
    if (!y && !q[1 - c].empty()) flag = 1;
    while (y > 0 || flag) {
      j = q[1 - c].front().first, k = q[1 - c].front().second, i = min(k, y);
      cout << x << " " << j << " " << i << endl;
      y -= i, k -= i, flag = 0;
      q[1 - c].pop();
    }
    if (!q[c].empty()) x = j, y = k, c = 1 - c;
  }
  while (!q[1 - c].empty()) {
    cout << q[1 - c].front().first << " " << x << " 0" << endl;
    q[1 - c].pop();
  }
  return 0;
}
