#include <bits/stdc++.h>
using namespace std;
map<int, int> B;
map<int, int> S;
map<int, int>::iterator it;
int main() {
  int a, b, c, d, e;
  char s[10];
  scanf("%d %d", &a, &b);
  for (c = 0; c < a; c++) {
    scanf("%s", s);
    scanf("%d", &d);
    scanf("%d", &e);
    if (s[0] == 'B') {
      B[d] += e;
    }
    if (s[0] == 'S') {
      S[d] += e;
    }
  }
  if (S.empty() == false) {
    for (a = 0, it = S.begin(); it != S.end() && a < b - 1; it++, a++) {
    }
    if (it == S.end()) {
      it--;
    }
    for (a = 0; a < b; it--, a++) {
      printf("S %d %d\n", it->first, it->second);
      if (it == S.begin()) {
        a = b;
      }
    }
  }
  if (B.empty() == false) {
    for (a = 0, it = B.end(), it--; a < b; it--, a++) {
      printf("B %d %d\n", it->first, it->second);
      if (it == B.begin()) {
        a = b;
      }
    }
  }
}
