#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, s, p, q;
  char d;
  vector<tuple<char, long long, long long>> b;
  cin >> n >> s;
  while (n--) {
    cin >> d >> p >> q;
    b.push_back(make_tuple(d, p, q));
  }
  sort(b.begin(), b.end(),
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<0>(left) > get<0>(right);
       });
  vector<tuple<char, long long, long long>>::iterator i = b.begin(), j;
  i = find_if(b.begin(), b.end(),
              [](const tuple<char, long long, long long> &e) {
                return get<0>(e) == 'B';
              });
  sort(b.begin(), i,
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<1>(left) < get<1>(right);
       });
  sort(i, b.end(),
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<1>(left) > get<1>(right);
       });
  for (j = b.begin() + 1; j < i; j++)
    if (get<1>(*j) == get<1>(*(j - 1))) {
      get<2>(*j) += get<2>(*(j - 1));
      b.erase(j - 1);
      i--;
      j--;
    }
  for (j = i + 1; j < b.end(); j++)
    if (get<1>(*j) == get<1>(*(j - 1))) {
      get<2>(*j) += get<2>(*(j - 1));
      b.erase(j - 1);
      j--;
    }
  for (j = b.begin(), n = 0; j != i && n < s; j++, n++)
    ;
  for (j = j - 1; j >= b.begin(); j--)
    cout << get<0>(*j) << " " << get<1>(*j) << " " << get<2>(*j) << "\n";
  for (j = i, n = 0; j != b.end() && n < s; j++, n++)
    cout << get<0>(*j) << " " << get<1>(*j) << " " << get<2>(*j) << "\n";
  return 0;
}
