#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
int s, b, w, N, B[100100], W[100100], C[100100], S[100100], connected[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])
      B[++B[0]] = i;
    else
      W[++W[0]] = i;
  }
  b = w = 1;
  while (b <= B[0] && w <= W[0]) {
    connected[W[w]] = connected[B[b]] = 1;
    if (S[B[b]] < S[W[w]]) {
      cout << B[b] << " " << W[w] << " " << S[B[b]] << endl;
      S[W[w]] -= S[B[b]];
      b++;
    } else {
      cout << B[b] << " " << W[w] << " " << S[W[w]] << endl;
      S[B[b]] -= S[W[w]];
      w++;
    }
  }
  while (b <= B[0]) {
    if (!connected[B[b]]) {
      cout << B[b] << " " << W[1] << " " << 0 << endl;
    }
    b++;
  }
  while (w <= W[0]) {
    if (!connected[W[w]]) {
      cout << B[1] << " " << W[w] << " " << 0 << endl;
    }
    w++;
  }
}
