#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
int a, b, s, N, S[100100], C[100100], A[100100], B[100100];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (int(i) = 1; (i) <= (N); (i)++) {
    cin >> C[i] >> S[i];
    if (C[i])
      A[++A[0]] = i;
    else
      B[++B[0]] = i;
  }
  a = b = 1;
  while (a <= A[0] && b <= B[0]) {
    s = min(S[A[a]], S[B[b]]);
    cout << A[a] << " " << B[b] << " " << s << endl;
    if (a == A[0] && b == B[0]) return 0;
    if (s < S[A[a]]) {
      b++;
      S[A[a]] -= s;
    } else if (s < S[B[b]]) {
      a++;
      S[B[b]] -= s;
    } else if (a == A[0]) {
      b++;
      S[A[a]] -= s;
    } else {
      a++;
      S[B[b]] -= s;
    }
  }
  return 0;
}
