#include <bits/stdc++.h>
using namespace std;
struct Z {
  char status;
  long price, quantity;
};
bool compare(Z a, Z b) { return (a.price > b.price); }
int main() {
  int n, s;
  cin >> n >> s;
  vector<Z> myVector;
  for (int i = 0; i < n; i++) {
    Z single;
    bool flag = true;
    cin >> single.status >> single.price >> single.quantity;
    for (int j = 0; j < myVector.size(); j++) {
      if (myVector[j].status == single.status &&
          myVector[j].price == single.price) {
        myVector[j].quantity = myVector[j].quantity + single.quantity;
        flag = false;
        break;
      }
    }
    if (flag) {
      myVector.push_back(single);
    }
  }
  sort(myVector.begin(), myVector.end(), compare);
  int b = myVector.size();
  for (int i = 0; i < myVector.size(); i++) {
    if (myVector[i].status == 'B') {
      b = i;
      break;
    }
  }
  for (int i = max(0, b - s); i < min(int(myVector.size()), b + s); i++) {
    cout << myVector[i].status << " " << myVector[i].price << " "
         << myVector[i].quantity << endl;
  }
  return 0;
}
