#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
int n;
vector<pair<int, int> > B;
vector<pair<int, int> > W;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int c = read(), s = read();
    if (c)
      B.push_back(make_pair(s, i));
    else
      W.push_back(make_pair(s, i));
  }
  sort(B.begin(), B.end());
  sort(W.begin(), W.end());
  for (int l = 0, r = 0; l < B.size() && r < W.size();) {
    int w = min(B[l].first, W[r].first);
    printf("%d %d %d\n", B[l].second, W[r].second, w);
    B[l].first -= w, W[r].first -= w;
    if (B[l].first == W[r].first && B[l].first == 0) {
      if (l + 1 < B.size())
        l++;
      else
        r++;
      continue;
    }
    if (!B[l].first)
      l++;
    else
      r++;
  }
}
