#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
using namespace std;
const int N = 100050, INF = 0x3f3f3f3f;
int n, col, sum, n1, n2;
struct node {
  int color, val, id;
  friend bool operator<(node x, node y) { return x.val < y.val; }
} white[N], black[N];
int min(int x, int y) { return (x > y) ? y : x; }
signed main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) {
    scanf("%d%d", &col, &sum);
    if (col)
      white[++n1] = node{col, sum, i};
    else
      black[++n2] = node{col, sum, i};
  }
  sort(white + 1, white + 1 + n1);
  sort(black + 1, black + 1 + n2);
  for (register int i = 1, j = 1; i <= n1 && j <= n2;) {
    int now = min(white[i].val, black[j].val);
    cout << white[i].id << " " << black[j].id << " " << now << endl;
    white[i].val -= now;
    black[j].val -= now;
    if (white[i].val)
      j++;
    else if (black[j].val)
      i++;
    else if (i < n1)
      i++;
    else
      j++;
  }
  return 0;
}
