#include <bits/stdc++.h>
using namespace std;
map<char, map<int, int> > mp, mp1;
vector<pair<int, pair<char, int> > > B, S;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int n, s;
  cin >> n >> s;
  vector<pair<char, pair<int, int> > > vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second.first >> vec[i].second.second;
    mp[vec[i].first][vec[i].second.first] += vec[i].second.second;
  }
  for (int i = 0; i < n; i++) {
    if (!mp1[vec[i].first][vec[i].second.first]) {
      mp1[vec[i].first][vec[i].second.first] = 1;
      if (vec[i].first == 'B') {
        B.push_back(make_pair(
            vec[i].second.first,
            make_pair(vec[i].first, mp[vec[i].first][vec[i].second.first])));
      } else {
        S.push_back(make_pair(
            vec[i].second.first,
            make_pair(vec[i].first, mp[vec[i].first][vec[i].second.first])));
      }
    }
  }
  int c = 0;
  sort(B.begin(), B.end());
  sort(S.begin(), S.end());
  if (S.size() != 0) {
    if (S.size() <= s) {
      for (int i = S.size() - 1; i >= 0; i--) {
        cout << S[i].second.first << " " << S[i].first << " "
             << S[i].second.second << endl;
      }
    } else {
      for (int i = s - 1; i >= 0; i--) {
        cout << S[i].second.first << " " << S[i].first << " "
             << S[i].second.second << endl;
      }
    }
  }
  if (B.size() != 0) {
    if (B.size() <= s) {
      for (int i = B.size() - 1; i >= 0; i--) {
        cout << B[i].second.first << " " << B[i].first << " "
             << B[i].second.second << endl;
      }
    } else {
      for (int i = B.size() - 1; c < s; i--) {
        cout << B[i].second.first << " " << B[i].first << " "
             << B[i].second.second << endl;
        c++;
      }
    }
  }
  return 0;
}
