#include <bits/stdc++.h>
using namespace std;
map<int, int> k;
map<int, int> l;
int x[1110111], y[1110111], a[1110111], b[1110111], sz, sz2;
int main() {
  int n, s;
  char c;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> c >> x[i] >> y[i];
    if (c == 'S') {
      if (k[x[i]] == 0) a[++sz] = x[i];
      k[x[i]] += y[i];
    }
    if (c == 'B') {
      if (l[x[i]] == 0) b[++sz2] = x[i];
      l[x[i]] += y[i];
    }
  }
  sort(a + 1, a + sz + 1);
  for (int i = min(s, sz); i >= 1; i--) {
    int u = k[a[i]];
    k[a[i]] -= l[a[i]];
    l[a[i]] -= u;
    if (k[a[i]] > 0) cout << "S " << a[i] << " " << k[a[i]] << endl;
  }
  sort(b + 1, b + sz2 + 1);
  for (int i = sz2; i >= sz2 - min(s, sz2) + 1; i--) {
    if (l[b[i]] > 0) cout << "B " << b[i] << " " << l[b[i]] << endl;
  }
  return 0;
}
