#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> b;
  map<int, int> s;
  map<int, int> e;
  int i = 0, t2, t3, f1 = m, f2 = m;
  char t1;
  for (i = 0; i < n; i++) {
    cin >> t1 >> t2 >> t3;
    if (t1 == 'B') {
      b[t2] += t3;
    } else {
      s[t2] += t3;
    }
  }
  int cnt = m;
  map<int, int>::reverse_iterator it;
  map<int, int>::iterator it2;
  if (m >= s.size()) {
    for (it = s.rbegin(); it != s.rend(); it++) {
      cout << "S"
           << " " << it->first << " " << it->second << "\n";
    }
  }
  cnt = m;
  if (m < s.size()) {
    for (it2 = s.begin(); it2 != s.end(); it2++) {
      if (cnt > 0) {
        e[it2->first] = it2->second;
        cnt--;
      } else {
        break;
      }
    }
    for (it = e.rbegin(); it != e.rend(); it++) {
      cout << "S"
           << " " << it->first << " " << it->second << "\n";
    }
  }
  if (m >= b.size()) {
    for (it = b.rbegin(); it != b.rend(); it++) {
      cout << "B"
           << " " << it->first << " " << it->second << "\n";
    }
  }
  cnt = m;
  if (m < b.size()) {
    for (it = b.rbegin(); it != b.rend(); it++) {
      if (cnt > 0) {
        cout << "B"
             << " " << it->first << " " << it->second << "\n";
        cnt--;
      } else {
        break;
      }
    }
  }
  return 0;
}
