#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 17;
const int INF = 1e9 + 17;
int n, s, x, y;
vector<pair<int, int> > v, V, vv, VV;
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c >> x >> y;
    if (c == 'S')
      v.push_back(make_pair(x, y));
    else
      V.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  sort(V.begin(), V.end());
  for (int i = 0; i < v.size(); ++i) {
    int k = i, Sum = 0;
    while (k + 1 < v.size()) {
      if (v[i].first == v[k + 1].first)
        k++, Sum += v[k].second;
      else
        break;
    }
    VV.push_back(make_pair(v[i].first, Sum + v[i].second));
    i = k;
  }
  sort(VV.begin(), VV.end());
  for (int i = min(s, int(VV.size())) - 1; i >= 0; --i)
    printf("S %d %d\n", VV[i].first, VV[i].second);
  for (int i = 0; i < V.size(); ++i) {
    int k = i, Sum = 0;
    while (k + 1 < V.size()) {
      if (V[i].first == V[k + 1].first)
        k++, Sum += V[k].second;
      else
        break;
    }
    vv.push_back(make_pair(V[i].first, Sum + V[i].second));
    i = k;
  }
  sort(vv.begin(), vv.end());
  reverse(vv.begin(), vv.end());
  for (int i = 0; i < min(s, int(vv.size())); ++i)
    printf("B %d %d\n", vv[i].first, vv[i].second);
  return 0;
}
