#include <bits/stdc++.h>
using namespace std;
long long ar[1111111], br[1111111];
char chr[1111111], dhr[1111111], ans1[11111];
pair<long long, long long> ans[111111];
int main() {
  long long maxx, maxx1, n, s, i, j, inp, inq;
  cin >> n >> s;
  char ch;
  maxx = maxx1 = INT_MIN;
  memset(ar, 0, sizeof(ar));
  memset(br, 0, sizeof(br));
  while (n--) {
    cin >> ch >> inp >> inq;
    if (ch == 'S') {
      chr[inp] = ch;
      ar[inp] += inq;
    } else {
      dhr[inp] = ch;
      br[inp] += inq;
    }
  }
  int coun = 0;
  for (i = 0; i <= 111111; i++) {
    if (ar[i] > 0) {
      coun++;
      ans[coun] = make_pair(i, ar[i]);
      ans1[coun] = chr[i];
    }
    if (coun == s) break;
  }
  for (i = coun; i > 0; i--)
    cout << ans1[i] << " " << ans[i].first << " " << ans[i].second << endl;
  coun = 0;
  for (i = 111111; i >= 0; i--) {
    if (br[i] > 0) {
      cout << dhr[i] << " " << i << " " << br[i] << endl;
      coun++;
    }
    if (coun == s) break;
  }
}
