#include <bits/stdc++.h>
using namespace std;
int N;
multimap<int, int> V[2];
int main() {
  cin >> N;
  int c, v;
  for (int i = 1; i <= N; i++) {
    cin >> c >> v;
    V[c].insert(make_pair(v, i));
  }
  while (V[0].size() > 0 && V[1].size() > 0) {
    int goal = (V[0].begin()->first < V[1].begin()->first) ? 0 : 1;
    if (V[1 - goal].begin()->first == (--V[1 - goal].end())->first &&
        V[1 - goal].size() != 1)
      goal = 1 - goal;
    int key = V[goal].begin()->first;
    multimap<int, int>::iterator F = V[1 - goal].upper_bound(key);
    if (F == V[1 - goal].end()) F--;
    cout << F->second << " " << V[goal].begin()->second << " " << key << endl;
    V[1 - goal].insert(make_pair(F->first - key, F->second));
    V[1 - goal].erase(F);
    V[goal].erase(V[goal].begin());
  }
  return 0;
}
