#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int color, sum;
  vector<pair<int, int> > v[2];
  for (int i = 0; i < n; i++) {
    cin >> color >> sum;
    v[color].push_back(pair<int, int>(sum, i + 1));
  }
  sort(v[0].begin(), v[0].end());
  sort(v[1].begin(), v[1].end());
  int min = 0;
  for (int i = 0, j = 0; i + j != n - 1;) {
    min = v[0][i].first;
    if (min > v[1][j].first) {
      min = v[1][j].first;
    }
    cout << v[0][i].second << " " << v[1][j].second << " " << min << endl;
    v[0][i].first -= min;
    v[1][j].first -= min;
    if (v[0][i].first < v[1][j].first) {
      i++;
    } else if (v[0][i].first > v[1][j].first) {
      j++;
    } else if (i < v[0].size() - 1) {
      i++;
    } else {
      j++;
    }
  }
  return 0;
}
