#include <bits/stdc++.h>
using namespace std;
struct lol {
  long long c, n, m, v;
  char d;
};
vector<lol> a, s;
vector<lol> b;
int ans, n, l, r, rr, S;
bool comp(lol a, lol b) { return (a.c > b.c || (a.c == b.c && a.n < b.n)); }
bool compp(lol a, lol b) { return (a.c < b.c || (a.c == b.c && a.n < b.n)); }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> S;
  for (int i = 0; i < n; i++) {
    lol t;
    cin >> t.d >> t.c >> t.v;
    t.n = i;
    if (t.d == 'B') {
      b.push_back(t);
    } else {
      s.push_back(t);
    }
  }
  sort(b.begin(), b.end(), comp);
  sort(s.begin(), s.end(), compp);
  for (int i = 1; i < b.size(); i++) {
    if (b[i].c == b[i - 1].c) {
      b[i - 1].v += b[i].v;
      b.erase(b.begin() + i);
      i--;
    }
  }
  for (int i = 1; i < s.size(); i++) {
    if (s[i].c == s[i - 1].c) {
      s[i - 1].v += s[i].v;
      s.erase(s.begin() + i);
      i--;
    }
  }
  int x = s.size();
  sort(s.begin(), s.begin() + min(x, S), comp);
  for (int i = 0; i < min(S, x); i++) {
    cout << s[i].d << ' ' << s[i].c << ' ' << s[i].v << endl;
  }
  x = b.size();
  for (int i = 0; i < min(S, x); i++) {
    cout << b[i].d << ' ' << b[i].c << ' ' << b[i].v << endl;
  }
  return 0;
}
