#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  vector<pair<long long int, int> > B, W;
  for (int i = 0; i < N; i++) {
    int c, s;
    scanf("%d %d", &c, &s);
    if (c == 0)
      B.push_back(make_pair(s, i));
    else
      W.push_back(make_pair(s, i));
  }
  sort(B.rbegin(), B.rend());
  sort(W.rbegin(), W.rend());
  while (B.size() > 0 && W.size() > 0) {
    auto b = B.back();
    B.pop_back();
    auto w = W.back();
    W.pop_back();
    long long int wt = min(b.first, w.first);
    printf("%d %d %lld\n", b.second + 1, w.second + 1, wt);
    b.first -= wt;
    w.first -= wt;
    if (b.first > 0)
      B.push_back(b);
    else if (w.first > 0)
      W.push_back(w);
    else if (B.size() > W.size())
      W.push_back(w);
    else
      B.push_back(b);
  }
  return 0;
}
