#include <bits/stdc++.h>
using namespace std;
const int NN = (int)1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = (long long)1e9 + 5;
vector<int> a[2];
int L[2];
int R[2];
int sum[NN];
bool cmp(const int& A, const int& B) { return sum[A] < sum[B]; }
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int c, v;
    scanf("%d%d", &c, &v);
    a[c].push_back(i);
    sum[i] = v;
  }
  sort(a[0].begin(), a[0].end(), cmp);
  sort(a[1].begin(), a[1].end(), cmp);
  R[0] = (int)a[0].size() - 1, R[1] = (int)a[1].size() - 1;
  L[0] = L[1] = 0;
  int node = a[0][R[0]--];
  int c = 0;
  vector<vector<int> > ans;
  for (; ans.size() < n - 1;) {
    int& idx_other = L[c ^ 1];
    while (idx_other < R[c ^ 1] && (sum[a[c ^ 1][idx_other]] == 0 ||
                                    sum[node] - sum[a[c ^ 1][idx_other]] > 0)) {
      ans.push_back({node, a[c ^ 1][idx_other], sum[a[c ^ 1][idx_other]]});
      sum[node] -= sum[a[c ^ 1][idx_other]];
      sum[a[c ^ 1][idx_other]] = 0;
      idx_other++;
    }
    int pre = node;
    node = a[c ^ 1][R[c ^ 1]--];
    ans.push_back({node, pre, sum[pre]});
    sum[node] -= sum[pre];
    sum[pre] = 0;
    c = c ^ 1;
  }
  for (auto& x : ans) {
    printf("%d %d %d\n", x[0], x[1], x[2]);
  }
  return 0;
}
