#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[2];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int t, k;
    scanf("%d%d", &t, &k);
    v[t].push_back(make_pair(k, i));
  }
  sort(v[0].begin(), v[0].end());
  sort(v[1].begin(), v[1].end());
  for (int i = 0, j = 0; i < v[0].size() && j < v[1].size();) {
    int k = min(v[0][i].first, v[1][j].first);
    printf("%d %d %d\n", v[0][i].second, v[1][j].second, k);
    v[0][i].first -= k, v[1][j].first -= k;
    if (v[0][i].first)
      j++;
    else if (v[1][j].first)
      i++;
    else if (i + 1 < v[0].size())
      i++;
    else
      j++;
  }
}
