#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void fast() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
}
void online_judge() {}
const int flag_max = 0x3f3f3f3f;
const long long OO = 2e9 + 10;
const double EPS = (1e-8);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const long long MOD = 1e9 + 7;
long long Power(long long n, long long deg) {
  if (!deg)
    return 1;
  else if (deg & 1)
    return (Power(n, deg - 1) * n) % MOD;
  else {
    long long half = Power(n, deg / 2) % MOD;
    return ((half * half) % MOD);
  }
  return 0;
}
map<pair<char, long long>, long long> order;
int main() {
  fast();
  int n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    char a;
    int x, y;
    cin >> a >> x >> y;
    order[{a, x}] += y;
  }
  vector<pair<long long, long long> > out, in;
  for (auto x : order) {
    if (x.first.first == 'S') {
      in.push_back({x.first.second, x.second});
    } else {
      out.push_back({x.first.second, x.second});
    }
  }
  sort(((in).begin()), ((in).end()));
  sort(out.rbegin(), out.rend());
  if (s > in.size()) {
    for (int i = in.size() - 1; i >= 0; i--)
      cout << 'S' << " " << in[i].first << " " << in[i].second << '\n';
  } else {
    for (int i = s - 1; i >= 0; i--)
      cout << "S " << in[i].first << " " << in[i].second << '\n';
  }
  for (int i = 0; i < out.size() && i < s; i++)
    cout << "B " << out[i].first << " " << out[i].second << '\n';
  return 0;
}
