#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 110;
int c[N], s[N], sum[2];
vector<int> a[2];
vector<pair<pair<int, int>, int> > edge;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> s[i];
    a[c[i]].push_back(i);
  }
  int id;
  while (!a[0].empty() && !a[1].empty()) {
    if (s[a[0].back()] >= s[a[1].back()]) {
      edge.push_back(
          make_pair(make_pair(a[0].back(), a[1].back()), s[a[1].back()]));
      s[a[0].back()] -= s[a[1].back()];
      id = a[1].back();
      a[1].pop_back();
    } else {
      edge.push_back(
          make_pair(make_pair(a[0].back(), a[1].back()), s[a[0].back()]));
      s[a[1].back()] -= s[a[0].back()];
      a[0].pop_back();
    }
  }
  a[0].pop_back();
  while (!a[0].empty()) {
    edge.push_back(make_pair(make_pair(a[0].back(), id), 0));
    a[0].pop_back();
  }
  for (int i = 0; i < n - 1; i++) {
    cout << edge[i].first.first + 1 << " " << edge[i].first.second + 1 << " "
         << edge[i].second << "\n";
  }
  cout << "\n";
  return 0;
}
