#include <bits/stdc++.h>
using namespace std;
map<int, int> s, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int cntb, cnts;
  cntb = cnts = 0;
  for (int i = 1; i <= n; i++) {
    char x;
    int q, w;
    cin >> x >> q >> w;
    if (x == 'B') {
      if (!b[-q]) {
        cntb++;
      }
      b[-q] += w;
    } else {
      if (!s[-q]) {
        cnts++;
      }
      s[-q] += w;
    }
  }
  cntb = min(cntb, m);
  if (cnts >= m) {
    cnts -= m;
  } else
    cnts = 0;
  for (map<int, int>::iterator i = s.begin(); i != s.end(); i++) {
    if (cnts) {
      cnts--;
      continue;
    }
    cout << "S " << -i->first << " " << i->second << '\n';
  }
  for (map<int, int>::iterator i = b.begin(); i != b.end(); i++) {
    cout << "B " << -i->first << " " << i->second << '\n';
    cntb--;
    if (!cntb) {
      break;
    }
  }
}
