#include<stdio.h>
#include<iostream>
#include<algorithm>
typedef long long ll;
struct order{
char ch;
ll p,q;
};
bool sorting(order a,order b)
{
return a.p>b.p;
}
int main()
{
using namespace std;
ll n,s5,i=0,b1=0,s1=0,countb=0,counts=0,f1=0,f2=0;
struct order ar[1005],b[1005],s[1005],fb[1005],fs[1005];
scanf("%lld%lld",&n,&s5);
while(n--)
{
cin>>ar[i].ch>>ar[i].p>>ar[i].q;
if(ar[i].ch=='B')
{
b[b1].ch='B';
b[b1].p=ar[i].p;
b[b1].q=ar[i].q;
b1++;
}
else
{
s[s1].ch='S';
s[s1].p=ar[i].p;
s[s1].q=ar[i].q;
s1++;
}
i++;
}
sort(b,b+b1,sorting);
sort(s,s+s1,sorting);
for(i=1;i<=b1;i++)
{
if(b[i].p==b[i-1].p)
{
b[i].ch='B';
b[i].p=b[i].p;
b[i].q=b[i].q+b[i-1].q;
}
else
{
fb[f1].ch='B';
fb[f1].p=b[i-1].p;
fb[f1].q=b[i-1].q;
countb++;
f1++;
}
}
for(i=1;i<=s1;i++)
{
if(s[i].p==s[i-1].p)
{
s[i].ch='S';
s[i].p=s[i].p;
s[i].q=s[i].q+s[i-1].q;
}
else
{
fs[f2].ch='S';
fs[f2].p=s[i-1].p;
fs[f2].q=s[i-1].q;
counts++;
f2++;
}
}
if(f2>s5)
{
for(i=0;i<s5;i++)
{
cout<<fs[i].ch<<" "<<fs[i].p<<" "<<fs[i].q;
printf("\n");
}
}
else
{
for(i=0;i<f2;i++)
{
cout<<fs[i].ch<<" "<<fs[i].p<<" "<<fs[i].q;
printf("\n");
}
}
if(f1>s5)
{
for(i=0;i<s5;i++)
{
cout<<fb[i].ch<<" "<<fb[i].p<<" "<<fb[i].q;
printf("\n");
}
}
else
{
for(i=0;i<f1;i++)
{
cout<<fb[i].ch<<" "<<fb[i].p<<" "<<fb[i].q;
printf("\n");
}
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KdHlwZWRlZiBsb25nIGxvbmcgbGw7CnN0cnVjdCBvcmRlcnsKICAgIGNoYXIgY2g7CiAgICBsbCBwLHE7Cn07CmJvb2wgc29ydGluZyhvcmRlciBhLG9yZGVyIGIpCnsKICAgIHJldHVybiBhLnA+Yi5wOwp9CmludCBtYWluKCkKewogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgIGxsIG4sczUsaT0wLGIxPTAsczE9MCxjb3VudGI9MCxjb3VudHM9MCxmMT0wLGYyPTA7CiAgICBzdHJ1Y3Qgb3JkZXIgYXJbMTAwNV0sYlsxMDA1XSxzWzEwMDVdLGZiWzEwMDVdLGZzWzEwMDVdOwogICAgc2NhbmYoIiVsbGQlbGxkIiwmbiwmczUpOwogICAgd2hpbGUobi0tKQogICAgewogICAgICAgIGNpbj4+YXJbaV0uY2g+PmFyW2ldLnA+PmFyW2ldLnE7CiAgICAgICAgaWYoYXJbaV0uY2g9PSdCJykKICAgICAgICB7CiAgICAgICAgICAgIGJbYjFdLmNoPSdCJzsKICAgICAgICAgICAgYltiMV0ucD1hcltpXS5wOwogICAgICAgICAgICBiW2IxXS5xPWFyW2ldLnE7CiAgICAgICAgICAgIGIxKys7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHNbczFdLmNoPSdTJzsKICAgICAgICAgICAgc1tzMV0ucD1hcltpXS5wOwogICAgICAgICAgICBzW3MxXS5xPWFyW2ldLnE7CiAgICAgICAgICAgIHMxKys7CiAgICAgICAgfQogICAgICAgIGkrKzsKICAgIH0KICAgIHNvcnQoYixiK2IxLHNvcnRpbmcpOwogICAgc29ydChzLHMrczEsc29ydGluZyk7CiAgICBmb3IoaT0xO2k8PWIxO2krKykKICAgIHsKICAgICAgICBpZihiW2ldLnA9PWJbaS0xXS5wKQogICAgICAgIHsKICAgICAgICAgICAgYltpXS5jaD0nQic7CiAgICAgICAgICAgIGJbaV0ucD1iW2ldLnA7CiAgICAgICAgICAgIGJbaV0ucT1iW2ldLnErYltpLTFdLnE7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgZmJbZjFdLmNoPSdCJzsKICAgICAgICBmYltmMV0ucD1iW2ktMV0ucDsKICAgICAgICBmYltmMV0ucT1iW2ktMV0ucTsKICAgICAgICBjb3VudGIrKzsKICAgICAgICBmMSsrOwogICAgfQogICAgfQogICAgZm9yKGk9MTtpPD1zMTtpKyspCiAgICB7CiAgICAgICAgaWYoc1tpXS5wPT1zW2ktMV0ucCkKICAgICAgICB7CiAgICAgICAgICAgIHNbaV0uY2g9J1MnOwogICAgICAgICAgICBzW2ldLnA9c1tpXS5wOwogICAgICAgICAgICBzW2ldLnE9c1tpXS5xK3NbaS0xXS5xOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGZzW2YyXS5jaD0nUyc7CiAgICAgICAgZnNbZjJdLnA9c1tpLTFdLnA7CiAgICAgICAgZnNbZjJdLnE9c1tpLTFdLnE7CiAgICAgICAgY291bnRzKys7CiAgICAgICAgZjIrKzsKICAgIH0KICAgIH0KICAgIGlmKGYyPnM1KQogICAgewogICAgICAgIGZvcihpPTA7aTxzNTtpKyspCiAgICAgICAgewogICAgICAgIGNvdXQ8PGZzW2ldLmNoPDwiICI8PGZzW2ldLnA8PCIgIjw8ZnNbaV0ucTsKICAgICAgICBwcmludGYoIlxuIik7CiAgICB9Cn0KICAgIGVsc2UKICAgIHsKICAgICAgICBmb3IoaT0wO2k8ZjI7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgY291dDw8ZnNbaV0uY2g8PCIgIjw8ZnNbaV0ucDw8IiAiPDxmc1tpXS5xOwogICAgICAgIHByaW50ZigiXG4iKTsKICAgICAgICB9CiAgICB9CiAgICBpZihmMT5zNSkKICAgIHsKICAgICAgICBmb3IoaT0wO2k8czU7aSsrKQogICAgICAgIHsKICAgICAgICBjb3V0PDxmYltpXS5jaDw8IiAiPDxmYltpXS5wPDwiICI8PGZiW2ldLnE7CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQp9CiAgICBlbHNlCiAgICB7CiAgICAgICAgZm9yKGk9MDtpPGYxO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQ8PGZiW2ldLmNoPDwiICI8PGZiW2ldLnA8PCIgIjw8ZmJbaV0ucTsKICAgICAgICBwcmludGYoIlxuIik7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=