#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Rec {
  int v, id;
} a[100005], b[100005];
int n, anum = 0, bnum = 0, flag[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int k, value;
    scanf("%d%d", &k, &value);
    if (k == 1) {
      a[++anum].v = value;
      a[anum].id = i;
    } else {
      b[++bnum].v = value;
      b[bnum].id = i;
    }
  }
  int i = 1, j = 1;
  while (i <= anum && j <= bnum) {
    cout << a[i].id << ' ' << b[j].id << ' ' << min(a[i].v, b[j].v) << endl;
    int k = min(a[i].v, b[j].v);
    a[i].v -= k;
    b[j].v -= k;
    flag[a[i].id] = flag[b[j].id] = 1;
    if (a[i].v == 0)
      i++;
    else
      j++;
  }
  for (; i <= anum; i++) {
    if (!flag[a[i].id]) cout << a[i].id << ' ' << b[1].id << " 0" << endl;
  }
  for (; j <= bnum; j++) {
    if (!flag[b[j].id]) cout << b[j].id << ' ' << a[1].id << " 0" << endl;
  }
  return 0;
}
