#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, s;
  cin >> n >> s;
  map<pair<char, long>, long> m;
  vector<pair<long, long> > S, B;
  for (int i = 0; i < n; ++i) {
    char ch;
    long p, q;
    cin >> ch >> p >> q;
    m[make_pair(ch, p)] += q;
  }
  map<pair<char, long>, long>::iterator it;
  for (it = m.begin(); it != m.end(); ++it) {
    if (it->first.first == 'S')
      S.push_back(make_pair(it->first.second, it->second));
    else
      B.push_back(make_pair(it->first.second, it->second));
  }
  sort(S.rbegin(), S.rend());
  sort(B.rbegin(), B.rend());
  for (int i = max(0l, (long)S.size() - s);
       i < min(s, (long)S.size()) + max(0l, (long)S.size() - s); ++i)
    cout << 'S' << ' ' << S[i].first << ' ' << S[i].second << endl;
  for (int i = 0; i < min(s, (long)B.size()); ++i)
    cout << 'B' << ' ' << B[i].first << ' ' << B[i].second << endl;
  return 0;
}
