#include <bits/stdc++.h>
using namespace std;
map<pair<char, long long>, long long> m;
map<pair<char, long long>, long long>::iterator it;
int main() {
  stack<pair<long long, long long> > qb, qs;
  long long n, s, a, b;
  cin >> n >> s;
  char c;
  for (int i = 0; i < (int)(n); i++) {
    cin >> c >> a >> b;
    m[make_pair(c, a)] += b;
  }
  for (it = m.begin(); it != m.end(); it++) {
    if (it->first.first == 'S') {
      if (qs.size() < s) qs.push(make_pair(it->first.second, it->second));
    } else
      qb.push(make_pair(it->first.second, it->second));
  }
  int i = s;
  while (i > 0 && !qs.empty()) {
    cout << "S " << qs.top().first << " " << qs.top().second << endl;
    qs.pop();
    i--;
  }
  while (s > 0 && !qb.empty()) {
    cout << "B " << qb.top().first << " " << qb.top().second << endl;
    qb.pop();
    s--;
  }
  return 0;
}
