#include <bits/stdc++.h>
using namespace std;
int n, s;
char ch[2];
pair<int, int> sell[60], buy[60];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    sl;
priority_queue<pair<int, int> > by;
int main() {
  while (scanf("%d%d", &n, &s) != EOF) {
    memset(sell, 0, sizeof sell);
    memset(buy, 0, sizeof buy);
    int u = -1, v = -1;
    while (n--) {
      int x, y;
      scanf("%s%d%d", ch, &x, &y);
      if (ch[0] == 'B') {
        by.push(make_pair(x, y));
      } else {
        sl.push(make_pair(x, y));
      }
    }
    if (!sl.empty()) {
      u++;
      sell[u] = sl.top();
      sl.pop();
      while (!sl.empty()) {
        if (sl.top().first == sell[u].first) {
          sell[u].second += sl.top().second;
          sl.pop();
        } else if (u + 1 < s) {
          sell[++u] = sl.top();
          sl.pop();
        } else
          break;
      }
    }
    if (!by.empty()) {
      v++;
      buy[v] = by.top();
      by.pop();
      while (!by.empty()) {
        if (by.top().first == buy[v].first) {
          buy[v].second += by.top().second;
          by.pop();
        } else if (v + 1 < s) {
          buy[++v] = by.top();
          by.pop();
        } else
          break;
      }
    }
    while (!sl.empty()) sl.pop();
    while (!by.empty()) by.pop();
    for (int i = u; i >= 0; i--) {
      printf("S %d %d\n", sell[i].first, sell[i].second);
    }
    for (int i = 0; i <= v; i++) {
      printf("B %d %d\n", buy[i].first, buy[i].second);
    }
  }
}
