#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int a, n;
int sum[MAXN];
int main() {
  vector<pair<int, int> > black;
  vector<pair<int, int> > white;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &a, &sum[i]);
    if (a == 0)
      white.push_back(make_pair(sum[i], i));
    else
      black.push_back(make_pair(sum[i], i));
  }
  sort(white.begin(), white.end());
  sort(black.begin(), black.end());
  for (int i = 0, j = 0; i < white.size() && j < black.size();) {
    int wid = white[i].second;
    int bid = black[j].second;
    int msum = min(sum[wid], sum[bid]);
    sum[wid] -= msum;
    sum[bid] -= msum;
    printf("%d %d %d\n", wid + 1, bid + 1, msum);
    if (i + 1 == white.size())
      ++j;
    else if (j + 1 == black.size())
      ++i;
    else {
      if (sum[wid] == 0)
        ++i;
      else
        ++j;
    }
  }
  return 0;
}
