#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
double Time() { return double(clock()) / double(CLOCKS_PER_SEC); }
int n;
vector<int> rl, rr;
vector<long long> rw;
queue<pair<int, long long> > w, b;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    long long cost;
    cin >> x >> cost;
    if (x)
      b.push(make_pair(i, cost));
    else
      w.push(make_pair(i, cost));
  }
  int r = 0;
  while (!w.empty() && !b.empty()) {
    if (r == n - 1) break;
    r++;
    int wi = w.front().first, bi = b.front().first;
    long long wc = w.front().second, bc = b.front().second;
    w.pop();
    b.pop();
    if (bc > wc || (bc == wc && b.size() <= w.size())) {
      rl.push_back(bi);
      rr.push_back(wi);
      rw.push_back(wc);
      b.push(make_pair(bi, bc - wc));
    } else {
      rl.push_back(bi);
      rr.push_back(wi);
      rw.push_back(bc);
      w.push(make_pair(wi, wc - bc));
    }
  }
  for (int i = 0; i < rw.size(); i++)
    cout << rl[i] << " " << rr[i] << " " << rw[i] << "\n";
  return 0;
}
