#include <bits/stdc++.h>
int main() {
  int i, j, N, M, s[3][2], c = 0, n = 0;
  scanf("%d%d", &N, &M);
  if (N > 4) c++;
  for (i = 0; i < N; i++) {
    for (j = 0; j < 2; j++) {
      scanf("%d", &s[i][j]);
      if (s[i][0] == 1) {
        n += (100 * s[i][1]);
      }
      if (s[i][0] == 2) n += (10 * s[i][1]);
      if (s[i][0] == 3) n += (s[i][1]);
    }
  }
  for (i = 0; i < N; i++) {
    printf("%d %d %d\n", n, c, s[i][1]);
  }
  if (n < 100) c++;
}
