#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
long long int inf = 1e18;
long long int n, m;
long long int binpow(long long int val, long long int deg) {
  if (deg < 0) return 0;
  if (!deg) return 1 % M;
  if (deg & 1) return binpow(val, deg - 1) * val % M;
  long long int res = binpow(val, deg >> 1);
  return (res * res) % M;
}
long long int modinv(long long int n) { return binpow(n, M - 2); }
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, j, t, k, x, y, z, N;
  cin >> n;
  vector<pair<long long int, long long int>> black, white;
  for (long long int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == 1) {
      black.push_back({y, i});
    } else {
      white.push_back({y, i});
    }
  }
  sort(black.begin(), black.end());
  sort(white.begin(), white.end());
  reverse(black.begin(), black.end());
  ;
  reverse(white.begin(), white.end());
  ;
  vector<tuple<long long int, long long int, long long int>> edge;
  i = 0;
  j = 0;
  long long int cnt = 0;
  long long int rem = 0;
  rem += black[i].first;
  while (i < black.size() && j < white.size()) {
    if (cnt == 0) {
      while (white[j].first < rem) {
        rem -= white[j].first;
        edge.push_back({black[i].second, white[j].second, white[j].first});
        j++;
      }
      edge.push_back({black[i].second, white[j].second, rem});
      rem = white[j].first - rem;
      if (rem == 0) {
        while (white[j + 1].first == 0 && j + 1 < white.size()) {
          edge.push_back({black[i].second, white[j + 1].second, 0});
          j++;
        }
      }
      i++;
    } else {
      while (black[i].first < rem) {
        rem -= black[i].first;
        edge.push_back({white[j].second, black[i].second, black[i].first});
        i++;
      }
      edge.push_back({white[j].second, black[i].second, rem});
      rem = black[i].first - rem;
      if (rem == 0) {
        while (black[i + 1].first == 0 && i + 1 < black.size()) {
          edge.push_back({white[j].second, black[i + 1].second, 0});
          i++;
        }
      }
      j++;
    }
    cnt ^= 1;
  }
  for (auto u : edge) {
    tie(x, y, z) = u;
    cout << x + 1 << " " << y + 1 << " " << z << '\n';
  }
  return 0;
}
