#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 100010;
const long double eps = 0.000000001;
pair<int, int> lis[2][MAX];
int main() {
  int n;
  cin >> n;
  int a, b;
  int c[2] = {0, 0};
  for (int i = (int)0; i < (int)(n); i++) {
    cin >> a >> b;
    lis[a][c[a]].first = -b;
    lis[a][c[a]].second = i + 1;
    c[a]++;
  }
  sort(lis[0], lis[0] + c[0]);
  sort(lis[1], lis[1] + c[1]);
  for (int i = (int)0; i < (int)(c[0]); i++) lis[0][i].first *= -1;
  for (int i = (int)0; i < (int)(c[1]); i++) lis[1][i].first *= -1;
  int pos[2] = {0, 0};
  int aux;
  while (pos[0] < c[0]) {
    cout << lis[0][pos[0]].second << " " << lis[1][pos[1]].second << " "
         << min(lis[0][pos[0]].first, lis[1][pos[1]].first) << endl;
    aux = min(lis[0][pos[0]].first, lis[1][pos[1]].first);
    lis[0][pos[0]].first -= aux;
    lis[1][pos[1]].first -= aux;
    if (lis[0][pos[0]].first == 0)
      pos[0]++;
    else
      pos[1]++;
  }
  pos[0]--;
  pos[1]++;
  while (pos[1] < c[1]) {
    cout << lis[0][pos[0]].second << " " << lis[1][pos[1]].second << " " << 0
         << endl;
    pos[1]++;
  }
}
