#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
  int v, id;
  bool operator<(const node &a) const { return v < a.v; }
};
vector<node> white, black;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int c, s;
    scanf("%d%d", &c, &s);
    if (c)
      white.push_back({s, i});
    else
      black.push_back({s, i});
  }
  sort(white.begin(), white.end());
  sort(black.begin(), black.end());
  int i = 0, j = 0;
  while (i < white.size() && j < black.size()) {
    int minv = min(white[i].v, black[j].v);
    printf("%d %d %d\n", white[i].id, black[j].id, minv);
    white[i].v -= minv;
    black[j].v -= minv;
    if (white[i].v)
      j++;
    else if (black[j].v)
      i++;
    else if (i < white.size() - 1)
      i++;
    else
      j++;
  }
  return 0;
}
