#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
queue<pair<int, int> > qu[2];
vector<pair<pair<int, int>, int> > ans;
vector<pair<int, int> > e[2];
int main() {
  int n, x, val;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &val);
    e[x].push_back(make_pair(val, i));
  }
  sort(e[0].begin(), e[0].end());
  sort(e[1].begin(), e[1].end());
  for (int i = 0; i < (int)e[0].size(); i++) {
    qu[0].push(make_pair(e[0][i].second, e[0][i].first));
  }
  for (int i = 0; i < (int)e[1].size(); i++) {
    qu[1].push(make_pair(e[1][i].second, e[1][i].first));
  }
  int root = qu[0].front().first, k = 1;
  val = qu[0].front().second;
  qu[0].pop();
  while (!qu[0].empty() || !qu[1].empty()) {
    while (1) {
      if (val >= qu[k].front().second) {
        val -= qu[k].front().second;
        int t = qu[k].front().first;
        ans.push_back(make_pair(make_pair(root, qu[k].front().first),
                                qu[k].front().second));
        qu[k].pop();
        if (qu[k].empty()) {
          val = 0;
          root = t;
          break;
        }
      } else {
        ans.push_back(make_pair(make_pair(root, qu[k].front().first), val));
        root = qu[k].front().first;
        val = qu[k].front().second - val;
        qu[k].pop();
        break;
      }
    }
    k = !k;
  }
  for (int i = 0; i < (int)ans.size(); i++) {
    printf("%d %d %d\n", ans[i].first.first, ans[i].first.second,
           ans[i].second);
  }
}
