#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int maxm = 1e6 + 100;
vector<pair<int, int> > a[2];
vector<pair<pair<int, int>, int> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, s;
    cin >> c >> s;
    a[c].push_back({s, i});
  }
  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());
  int i = 0, j = 0;
  while (i < a[0].size() && j < a[1].size()) {
    if (a[0][i].first < a[1][j].first) {
      ans.push_back({{a[0][i].second, a[1][j].second}, a[0][i].first});
      a[1][j].first -= a[0][i].first;
      a[0][i].first = 0;
      i++;
    } else {
      ans.push_back({{a[0][i].second, a[1][j].second}, a[1][j].first});
      a[0][i].first -= a[1][j].first;
      a[1][j].first = 0;
      j++;
    }
  }
  if (i == a[0].size()) {
    j++;
    while (j < a[1].size()) {
      ans.push_back({{a[0][i - 1].second, a[1][j].second}, 0});
      j++;
    }
  } else {
    i++;
    while (i < a[0].size()) {
      ans.push_back({{a[1][j - 1].second, a[0][i].second}, 0});
      i++;
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first.first + 1 << ' ' << ans[i].first.second + 1 << ' '
         << ans[i].second << endl;
  return 0;
}
