#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double g = 10.0, eps = 1e-4;
const int N = 100000 + 10, maxn = 500 + 100, inf = 0x3f3f3f;
pair<int, int> v[2][N];
int vv[2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int c, s;
    cin >> c >> s;
    v[c][++vv[c]] = make_pair(s, i);
  }
  sort(v[0] + 1, v[0] + 1 + vv[0]);
  sort(v[1] + 1, v[1] + 1 + vv[1]);
  for (int i = 1, j = 1; i <= vv[0] && j <= vv[1];) {
    int t = min(v[0][i].first, v[1][j].first);
    cout << v[0][i].second << " " << v[1][j].second << " " << t << endl;
    v[0][i].first -= t;
    v[1][j].first -= t;
    if (v[0][i].first)
      j++;
    else if (v[1][j].first)
      i++;
    else if (i < vv[0])
      i++;
    else
      j++;
  }
  return 0;
}
