#include <bits/stdc++.h>
using namespace std;
int n, cc, s, u[100001], v[100001], w[100001], nn, bb, ww, c[100001],
    ds[100001];
set<pair<int, int>> bl, wh;
int dsget(int v) { return (v == ds[v]) ? v : (ds[v] = dsget(ds[v])); }
void dsunion(int a, int b) {
  a = dsget(a);
  b = dsget(b);
  if (a != b) ds[a] = b;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cc >> s;
    c[i] = cc;
    if (cc == 1)
      bl.insert(make_pair(i, s)), bb = i;
    else
      wh.insert(make_pair(i, s)), ww = i;
  }
  for (int i = 0; i < n; i++) ds[i] = i;
  while (!bl.empty() && !wh.empty()) {
    pair<int, int> bp = (*bl.begin()), wp = (*wh.begin());
    int vich = min(bp.second, wp.second);
    u[nn] = bp.first;
    v[nn] = wp.first;
    w[nn] = vich;
    dsunion(u[nn], v[nn]);
    nn++;
    bp.second -= vich;
    wp.second -= vich;
    bl.erase(bl.begin());
    wh.erase(wh.begin());
    bl.insert(bp);
    wh.insert(wp);
    if (bp.second == 0)
      bl.erase(bl.begin());
    else if (wp.second == 0)
      wh.erase(wh.begin());
  }
  int r = dsget(ww);
  for (int i = 0; i < n; i++)
    if (dsget(i) != r && c[i] != c[ww]) {
      u[nn] = i;
      v[nn] = ww;
      w[nn] = 0;
      dsunion(u[nn], v[nn]);
      r = dsget(ww);
      nn++;
    }
  r = dsget(bb);
  for (int i = 0; i < n; i++)
    if (dsget(i) != r && c[i] != c[bb]) {
      u[nn] = i;
      v[nn] = bb;
      w[nn] = 0;
      dsunion(u[nn], v[nn]);
      r = dsget(bb);
      nn++;
    }
  for (int i = 0; i < nn; i++)
    cout << u[i] + 1 << " " << v[i] + 1 << " " << w[i] << endl;
}
