#include <bits/stdc++.h>
using namespace std;
map<char, map<int, int> > x;
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, d, p, q;
  cin >> n >> d;
  for (__typeof(n) i = 0; i < (n); ++i) {
    char ch;
    cin >> ch >> p >> q;
    x[ch][p] += q;
  }
  for (int i = 0, j = 0; i < 100001 && j < d; i++) {
    if (x['S'][i]) {
      j++;
      ans.push_back(make_pair(i, x['S'][i]));
    }
  }
  for (__typeof(0) i = (int)ans.size() - 1; i >= 0; i--)
    cout << "S " << ans[i].first << " " << ans[i].second << '\n';
  for (int i = 100001, j = 0; i >= 0 && j < d; i--) {
    if (x['B'][i]) {
      j++;
      cout << "B " << i << " " << x['B'][i] << '\n';
    }
  }
  return 0;
}
