#include <bits/stdc++.h>
using namespace std;
struct node {
  int v;
  int id;
  bool operator<(const node& W) const { return v > W.v; }
};
priority_queue<node> q0, q1;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int c, v;
    cin >> c >> v;
    if (c == 0)
      q0.push({v, i});
    else
      q1.push({v, i});
  }
  int id0, id1;
  int cnt = 0;
  while (q0.size() && q1.size()) {
    auto t1 = q0.top();
    auto t2 = q1.top();
    int v1 = t1.v, v2 = t2.v;
    q0.pop();
    q1.pop();
    id0 = t1.id, id1 = t2.id;
    if (v1 < v2) {
      cnt++;
      cout << id0 << " " << id1 << " " << v1 << endl;
      v2 -= v1;
      if (q0.size()) q1.push({v2, t2.id});
    } else {
      v1 -= v2;
      cnt++;
      cout << id0 << ' ' << id1 << " " << v2 << endl;
      if (q1.size()) q0.push({v1, t1.id});
    }
  }
  while (q0.size() && cnt < n - 1) {
    cnt++;
    auto t1 = q0.top();
    q0.pop();
    int v = t1.v;
    cout << t1.id << " " << id1 << " " << v << endl;
  }
  while (q1.size() && cnt < n - 1) {
    cnt++;
    auto t1 = q1.top();
    q1.pop();
    int v = t1.v;
    cout << t1.id << " " << id0 << " " << v << endl;
  }
  return 0;
}
