#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, s;
  node() { u = s = 0; }
  bool operator<(const node &temp) const {
    if (this->s < temp.s) return 1;
    return 0;
  }
};
node black[100005];
node white[100005];
vector<vector<node> > adj;
int main() {
  int n;
  scanf("%d", &n);
  adj.resize(n);
  bool allzero = true;
  int w, b;
  w = b = 0;
  for (int i = 0; i < n; ++i) {
    int c;
    scanf("%d", &c);
    if (c == 0) {
      white[w].u = i;
      scanf("%d", &white[w].s);
      if (white[w].s) allzero = false;
      ++w;
    } else {
      black[b].u = i;
      scanf("%d", &black[b].s);
      if (black[b].s) allzero = false;
      ++b;
    }
  }
  if (allzero) {
    if (w < b) {
      for (int i = 0; i < b; ++i)
        cout << white[0].u + 1 << ' ' << black[i].u + 1 << ' ' << 0 << endl;
      for (int i = 1; i < w; ++i)
        cout << white[i].u + 1 << ' ' << black[i].u + 1 << ' ' << 0 << endl;
    } else {
      for (int i = 0; i < w; ++i)
        cout << black[0].u + 1 << ' ' << white[i].u + 1 << ' ' << 0 << endl;
      for (int i = 1; i < b; ++i)
        cout << black[i].u + 1 << ' ' << white[i].u + 1 << ' ' << 0 << endl;
    }
    return 0;
  }
  sort(black, black + b);
  sort(white, white + w);
  for (int indb = 0, indw = 0; indb < b && indw < w;) {
    if (white[indw].s < black[indb].s) {
      black[indb].s -= white[indw].s;
      adj[black[indb].u].push_back(white[indw]);
      ++indw;
    } else {
      white[indw].s -= black[indb].s;
      adj[white[indw].u].push_back(black[indb]);
      ++indb;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < adj[i].size(); ++j) {
      printf("%d %d %d\n", i + 1, adj[i][j].u + 1, adj[i][j].s);
    }
  }
  return 0;
}
