#include <bits/stdc++.h>
using namespace std;
struct node {
  int volume;
  int value;
};
node S[100005];
node B[100005];
int cmp(node a, node b) { return a.value < b.value; }
int main() {
  char s;
  int n, m, ans, tmp, p, v, sum1, sum2;
  while (scanf("%d%d", &n, &m) != EOF) {
    sum1 = sum2 = 0;
    memset(S, 0, sizeof(S));
    memset(B, 0, sizeof(B));
    for (int i = 0; i < n; i++) {
      cin >> s >> p >> v;
      if (s == 'B') {
        B[p].volume += v;
      } else
        S[p].volume += v;
    }
    for (int i = 100005 - 1; i >= 0; i--) {
      if (S[i].volume) {
        sum1++;
      }
    }
    if (sum1 > m) {
      tmp = sum1 - m;
      for (int i = 100005 - 1; i >= 0; i--) {
        if (S[i].volume && tmp) {
          S[i].volume = 0;
          tmp--;
        }
      }
    }
    for (int i = 100005 - 1; i >= 0; i--) {
      if (S[i].volume) cout << "S " << i << " " << S[i].volume << endl;
    }
    for (int i = 100005 - 1; i >= 0; i--) {
      if (B[i].volume && sum2 < m) {
        cout << "B " << i << " " << B[i].volume << endl;
        sum2++;
      }
    }
  }
  return 0;
}
