#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > b, w;
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long c, s;
    cin >> c >> s;
    if (c)
      b.push_back({i + 1, s});
    else
      w.push_back({i + 1, s});
  }
  for (long long bi = 0, wi = 0; bi < b.size() && wi < w.size();) {
    long long we = min(b[bi].second, w[wi].second);
    b[bi].second -= we;
    w[wi].second -= we;
    cout << b[bi].first << " " << w[wi].first << " " << we << "\n";
    if (b[bi].second == 0 && bi < b.size() - 1)
      bi++;
    else if (w[wi].second == 0 && wi < w.size() - 1)
      wi++;
    else if (bi == b.size() - 1 && wi == w.size() - 1)
      bi++, wi++;
  }
  return 0;
}
