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