#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int s[MAXN];
vector<pair<int, int> > vb, vw;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  int c;
  for (int i = 1; i < n + 1; ++i) {
    cin >> c >> s[i];
    if (c == 0) {
      vb.push_back(make_pair(s[i], i));
    } else
      vw.push_back(make_pair(s[i], i));
  }
  sort(vb.begin(), vb.end());
  sort(vw.begin(), vw.end());
  int i = 0, j = 0;
  int bo = 0;
  while (i != vb.size() && j != vw.size()) {
    int wt = min(vb[i].first, vw[j].first);
    cout << vb[i].second << " " << vw[j].second << " " << wt << endl;
    ;
    vb[i].first -= wt;
    vw[j].first -= wt;
    if (vb[i].first == 0 && i != vb.size() - 1)
      i++;
    else
      j++;
  }
}
