#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 99;
int n, x, y, p, cnt, ans[N][3], g;
vector<pair<int, int> > v1, v2;
int main() {
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    cin >> x >> y;
    if (x)
      v2.push_back(make_pair(i, y));
    else
      v1.push_back(make_pair(i, y));
  }
  for (long long i = 0; i < v1.size(); i++) {
    p--;
    g = 1;
    while (g || v1[i].second || (i == v1.size() - 1 && p < v2.size() - 1)) {
      p++, g = 0;
      ans[cnt][0] = v1[i].first;
      ans[cnt][1] = v2[p].first;
      ans[cnt++][2] = min(v1[i].second, v2[p].second);
      int s = v1[i].second;
      v1[i].second -= min(v1[i].second, v2[p].second);
      v2[p].second -= min(s, v2[p].second);
    }
  }
  for (long long i = 0; i < cnt; i++)
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
}
