#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
vector<pair<int, int> > a, b;
int main() {
  int n;
  cin >> n;
  for (int i = 1, col, w; i <= n; i++) {
    scanf("%d%d", &col, &w);
    if (col)
      a.push_back(make_pair(w, i));
    else
      b.push_back(make_pair(w, i));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int cnt1 = 0, cnt2 = 0;
  int up1 = a.size();
  int up2 = b.size();
  while (cnt1 < up1 && cnt2 < up2) {
    int tmp = min(a[cnt1].first, b[cnt2].first);
    printf("%d %d %d\n", a[cnt1].second, b[cnt2].second, tmp);
    a[cnt1].first -= tmp;
    b[cnt2].first -= tmp;
    if (a[cnt1].first == 0 && cnt1 < up1 - 1)
      cnt1++;
    else if (b[cnt2].first == 0 && cnt2 < up2 - 1)
      cnt2++;
    else if (cnt1 < up1 - 1)
      cnt1++;
    else
      cnt2++;
  }
  return 0;
}
