#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, s;
  cin >> n >> s;
  map<int, int> buy, sell;
  for (int i = 0; i < n; i++) {
    char d;
    int p, q;
    cin >> d >> p >> q;
    if (d == 'B')
      buy[p] += q;
    else
      sell[p] += q;
  }
  vector<pair<int, int> > a, b;
  int ct = 0;
  for (map<int, int>::reverse_iterator it = buy.rbegin(); it != buy.rend();
       it++) {
    ct++;
    a.push_back(make_pair((*it).first, (*it).second));
    if (ct == s) break;
  }
  ct = 0;
  for (map<int, int>::iterator it = sell.begin(); it != sell.end(); it++) {
    ct++;
    b.push_back(make_pair((*it).first, (*it).second));
    if (ct == s) break;
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  sort(b.begin(), b.end(), greater<pair<int, int> >());
  int sz = b.size();
  for (int i = 0; i < sz; i++)
    cout << "S"
         << " " << b[i].first << " " << b[i].second << endl;
  sz = a.size();
  for (int i = 0; i < sz; i++)
    cout << "B"
         << " " << a[i].first << " " << a[i].second << endl;
  return 0;
}
