#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > G[1000000];
int check, i, j, c, s, n, sum;
bool flag1, flag2;
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &c, &s);
    sum += s;
    G[c].push_back(make_pair(s, i + 1));
  }
  sort(G[0].begin(), G[0].end());
  sort(G[1].begin(), G[1].end());
  i = 0;
  j = 0;
  check = -1;
  while (i < G[0].size() && j < G[1].size()) {
    if (G[0][i].first == G[1][j].first) {
      cout << G[0][i].second << " " << G[1][j].second << " " << G[1][j].first
           << endl;
      if (G[0].size() - i >= G[1].size() - j) {
        G[1][j].first = 0;
        i++;
      } else {
        G[0][i].first = 0;
        j++;
      }
      continue;
    }
    if (G[0][i].first > G[1][j].first) {
      cout << G[0][i].second << " " << G[1][j].second << " " << G[1][j].first
           << endl;
      G[0][i].first -= G[1][j].first;
      j++;
    } else {
      cout << G[0][i].second << " " << G[1][j].second << " " << G[0][i].first
           << endl;
      G[1][j].first -= G[0][i].first;
      i++;
    }
  }
}
