#include <bits/stdc++.h>
using namespace std;
int n, s, p, q;
char ch;
vector<pair<int, int>> v;
map<int, int> B, S;
int main() {
  cin >> n >> s;
  while (n--) {
    cin >> ch >> p >> q;
    if (ch == 'B')
      B[p] += q;
    else
      S[p] += q;
  }
  for (auto it : S) v.push_back({it.first, it.second});
  sort(v.begin(), v.end());
  reverse(v.begin(), min(v.begin() + s, v.end()));
  for (int i = 0; i < min(int(v.size()), s); i++)
    cout << "S " << v[i].first << " " << v[i].second << endl;
  v.clear();
  for (auto it : B) v.push_back({it.first, it.second});
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < min(int(v.size()), s); i++)
    cout << "B " << v[i].first << " " << v[i].second << endl;
  return 0;
}
