#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<int, int> &pr1, const pair<int, int> &pr2) {
  return pr1.second > pr2.second;
}
int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > black, white;
  for (int i = 0; i < N; i++) {
    int col, wgt;
    cin >> col >> wgt;
    if (col == 0) {
      white.push_back({i, wgt});
    } else {
      black.push_back({i, wgt});
    }
  }
  sort(white.begin(), white.end(), compare);
  sort(black.begin(), black.end(), compare);
  while (black.size() + white.size() > 1) {
    int bs = black.size(), ws = white.size();
    while (bs > 0 && ws > 0 && black[bs - 1].second >= white[ws - 1].second) {
      if (ws == 1 && bs > 1) {
        break;
      }
      cout << white[ws - 1].first + 1 << " " << black[bs - 1].first + 1 << " "
           << white[ws - 1].second << endl;
      black[bs - 1].second -= white[ws - 1].second;
      white.pop_back();
      ws = white.size();
    }
    while (ws > 0 && bs > 0 && white[ws - 1].second >= black[bs - 1].second) {
      if (bs == 1 && ws > 1) {
        break;
      }
      cout << white[ws - 1].first + 1 << " " << black[bs - 1].first + 1 << " "
           << black[bs - 1].second << endl;
      white[ws - 1].second -= black[bs - 1].second;
      black.pop_back();
      bs = black.size();
    }
  }
  return 0;
}
