#include <bits/stdc++.h>
using namespace std;
int dblcmp(double x) { return fabs(x) < 1e-8 ? 0 : x > 0 ? 1 : -1; }
bool insize(int c, int l, int r) {
  if (c >= l && c <= r) return true;
  return false;
}
template <class T>
inline void checkmin(T &a, T b) {
  if (a == -1 || a > b) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (a < b) a = b;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int N = 100001;
const int NN = 500500;
const int INF = 0x3f3f3f3f;
const int maxn = 2222;
template <class T>
inline void SD(T &x) {
  char c;
  int mul = 1;
  while ((c = getchar()) != EOF) {
    if (c == '-') mul = -1;
    if (c >= '0' && c <= '9') {
      x = c - '0';
      break;
    }
  }
  if (c == EOF) {
    x = EOF;
    return;
  }
  while ((c = getchar())) {
    if (c >= '0' && c <= '9') {
      x = (x << 1) + (x << 3) + (c - '0');
    } else
      break;
  }
  x *= mul;
};
set<pair<int, int> > a, b;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int bo, v;
    scanf("%d%d", &bo, &v);
    if (bo)
      a.insert(make_pair(v, i));
    else
      b.insert(make_pair(v, i));
  }
  while (a.size() + b.size() > 1) {
    if (a.begin()->first < b.begin()->first ||
        (a.begin()->first == b.begin()->first && a.size() >= b.size())) {
      int v = a.begin()->first;
      printf("%d %d %d\n", a.begin()->second, b.begin()->second, v);
      a.erase(a.begin());
      pair<int, int> x = *b.begin();
      b.erase(b.begin());
      x.first -= v;
      b.insert(x);
    } else {
      int v = b.begin()->first;
      printf("%d %d %d\n", a.begin()->second, b.begin()->second, v);
      b.erase(b.begin());
      pair<int, int> x = *a.begin();
      a.erase(a.begin());
      x.first -= v;
      a.insert(x);
    }
  }
}
