#include <bits/stdc++.h>
using namespace std;
struct stru {
  int color;
  int value;
  int node;
  bool operator<(const stru& a) const {
    if (value != a.value) return value < a.value;
    return node < a.node;
  }
} a[110000];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  multiset<stru> st[2];
  multiset<stru> all;
  for (int i = 0; i < n; i++) {
    cin >> a[i].color >> a[i].value;
    a[i].node = i;
    st[a[i].color].insert(a[i]);
    all.insert(a[i]);
  }
  for (int i = 1; i < n; i++) {
    stru b;
    if (st[0].size() > st[1].size())
      b = *st[0].begin();
    else
      b = *st[1].begin();
    st[b.color].erase(st[b.color].find(b));
    stru b2 = *(--st[1 - b.color].end());
    st[b2.color].erase(st[b2.color].find(b2));
    cout << b.node + 1 << " " << b2.node + 1 << " " << b.value << "\n";
    b2.value -= b.value;
    st[b2.color].insert(b2);
  }
  return 0;
}
