#include <bits/stdc++.h>
using namespace std;
struct tagst {
  int id, sum;
  bool operator<(const tagst &sta) const { return sta.sum < sum; }
};
vector<tagst> g_v[100100];
int fa[100100], col[100100];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  tagst sttmp, st[2];
  int f[2];
  int i, j, n;
  scanf("%d", &n);
  priority_queue<tagst> que[2];
  for (i = 1; i <= n; i++) {
    fa[i] = i;
    scanf("%d%d", &col[i], &sttmp.sum);
    sttmp.id = i;
    que[col[i]].push(sttmp);
  }
  while (que[0].size() && que[1].size()) {
    for (i = 0; i < 2; i++)
      st[i] = que[i].top(), que[i].pop(), f[i] = find(st[i].id);
    if (st[0].sum >= st[1].sum) {
      st[0].sum -= st[1].sum;
      fa[f[1]] = f[0];
      g_v[st[0].id].push_back(st[1]);
      if (st[0].sum) {
        que[0].push(st[0]);
      }
    } else {
      fa[f[0]] = f[1];
      st[1].sum -= st[0].sum;
      que[1].push(st[1]);
      g_v[st[1].id].push_back(st[0]);
    }
  }
  f[0] = find(1);
  for (i = 1; i <= n; i++) {
    if (f[0] != (f[1] = find(i))) {
      if (col[i] != col[f[0]])
        printf("%d %d 0\n", i, f[0]);
      else
        printf("%d %d 0\n", i, g_v[f[0]][0]);
      fa[f[1]] = f[0];
    }
    for (j = 0; j < g_v[i].size(); j++) {
      printf("%d %d %d\n", i, g_v[i][j].id, g_v[i][j].sum);
    }
  }
}
