#include <bits/stdc++.h>
using namespace std;
int a[100005];
vector<pair<int, int> > v[2];
int main() {
  int n, c, d;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &c, &d);
    v[c].push_back(make_pair(i + 1, d));
  }
  int i1 = 0, i2 = 0;
  for (int i = 1; i < n; i++) {
    d = min(v[0][i1].second, v[1][i2].second);
    printf("%d %d %d\n", v[0][i1].first, v[1][i2].first, d);
    v[1][i2].second -= d;
    v[0][i1].second -= d;
    if (i1 == v[0].size() - 1)
      i2++;
    else if (i2 == v[1].size() - 1)
      i1++;
    else if (v[0][i1].second < v[1][i2].second)
      i1++;
    else
      i2++;
  }
  return 0;
}
