#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > black, white;
int n, color, weight, iw = 0, ib = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &color, &weight);
    if (color == 1)
      black.push_back(make_pair(weight, i));
    else
      white.push_back(make_pair(weight, i));
  }
  for (int i = 0; i < n - 1; ++i) {
    if ((white[iw].first < black[ib].first) ||
        (white[iw].first == black[ib].first && iw + 1 != white.size())) {
      printf("%d %d %d\n", white[iw].second, black[ib].second, white[iw].first);
      black[ib].first -= white[iw++].first;
    } else {
      printf("%d %d %d\n", white[iw].second, black[ib].second, black[ib].first);
      white[iw].first -= black[ib++].first;
    }
  }
  return 0;
}
