#include <iostream>
#include <vector>

using namespace std;

vector <int> buy;
vector <int> sell;

int main(){
	buy.resize(100001, 0);
	sell.resize(100001, 0);
	int n, s, p, q;
	char d;
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		cin>>d>>p>>q;
		if(d == 'B'){
			buy[p] += q;
		}
		else{
			sell[p] += q;
		}
	}
	int counter = 0;
		for(int i = 100000; i >= 0; i--){
		if(sell[i] != 0){
			cout<<"S "<<i<<" "<<sell[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	counter = 0;
	for(int i = 100000; i >= 0; i--){
		if(buy[i] != 0){
			cout<<"B "<<i<<" "<<buy[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector <int> buy;
vector <int> sell;

int main(){
	buy.resize(100001, 0);
	sell.resize(100001, 0);
	int n, s, p, q;
	char d;
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		cin>>d>>p>>q;
		if(d == 'B'){
			buy[p] += q;
		}
		else{
			sell[p] += q;
		}
	}
	int counter = 0;
		for(int i = 0; i <= 100000; i++){
		if(sell[i] != 0){
			cout<<"S "<<i<<" "<<sell[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	counter = 0;
	for(int i = 100000; i >= 0; i--){
		if(buy[i] != 0){
			cout<<"B "<<i<<" "<<buy[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector <int> buy;
vector <int> sell;

int main(){
	buy.resize(100001, 0);
	sell.resize(100001, 0);
	int n, s, p, q;
	char d;
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		cin>>d>>p>>q;
		if(d == 'B'){
			buy[p] += q;
		}
		else{
			sell[p] += q;
		}
	}
	int counter = 0;
	for(int i = 100000; i >= 0; i--){
		if(buy[i] != 0){
			cout<<"B "<<i<<" "<<buy[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	counter = 0;
	for(int i = 100000; i >= 0; i--){
		if(sell[i] != 0){
			cout<<"S "<<i<<" "<<sell[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> buy;
vector <int> sell;
vector <pair <int, int> > ans_s;

int main(){
	buy.resize(100001, 0);
	sell.resize(100001, 0);
	int n, s, p, q;
	char d;
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		cin>>d>>p>>q;
		if(d == 'B'){
			buy[p] += q;
		}
		else{
			sell[p] += q;
		}
	}
	int counter = 0;
		for(int i = 0; i <= 100000; i++){
		if(sell[i] != 0){
			ans_s.push_back(make_pair(i, sell[i]));
			counter++;
		}
		if(counter >= s) break;
	}
	reverse(ans_s.begin(), ans_s.end());
	for(int i = 0; i < ans_s.size(); i++){
		cout<<"S "<<ans_s[i].first<<" "<<ans_s[i].second<<"\n";
	}
	counter = 0;
	for(int i = 100000; i >= 0; i--){
		if(buy[i] != 0){
			cout<<"B "<<i<<" "<<buy[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
	long long n, s;
	cin >> n >> s;
	map<long long, long long> buy;
	map<long long, long long> sell;
	for (long long i = 0; i < n; ++i) {
		char type;
		long long price, amount;
		cin >> type >> price >> amount;
		if (type == 'B')
			buy[price] += amount;
		else
			sell[price] += amount;
	}
	long long counter = 0;
	map<long long, long long> ascending_s;
	for (auto i = sell.begin(); i != sell.end() && counter != s; ++i) {
		ascending_s[i->first] = i->second;
		++counter;
	}
	for (auto i = ascending_s.rbegin(); i != ascending_s.rend(); ++i) {
		cout << "S " << i->first << ' ' << i->second << endl;
	}
	counter = 0;
	for (auto i = buy.rbegin(); i != buy.rend() && counter != s; ++i) {
		cout << "B " << i->first << ' ' << i->second << endl;
		++counter;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first, i.second });
	for (auto & i : sol)
		v2.push_back({ i.first, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end()); reverse(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "S" << ' ' << v2[i].first << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first * i.second, i.second });

	for (auto & i : sol)
		v2.push_back({ i.first * i.second, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end()); reverse(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "B" << ' ' << v2[i].first / v2[i].second << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "S" << ' ' << v1[i].first / v1[i].second << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first * i.second, i.second });

	for (auto & i : sol)
		v2.push_back({ i.first * i.second, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end()); reverse(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "S" << ' ' << v2[i].first / v2[i].second << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first / v1[i].second << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first, i.second });
	for (auto & i : sol)
		v2.push_back({ i.first, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "S" << ' ' << v2[i].first << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first, i.second });
	for (auto & i : sol)
		v2.push_back({ i.first, i.second });
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end()); reverse(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "S" << ' ' << v2[i].first << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first * i.second, i.second });

	for (auto & i : sol)
		v2.push_back({ i.first * i.second, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end()); reverse(v2.begin(), v2.end());
	for (int i = 0; i < v2.size() && i < s; i++)
		cout << "S" << ' ' << v2[i].first / v2[i].second << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first / v1[i].second << ' ' << v1[i].second << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#define forn(start, finish, step) for (int step = start; step < finish; step++)
#define ff first
#define ss second
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long

int n, s;
vector<pair<int, int> > v1, v2;
map<int, int> sol, buy;

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	cin >> n >> s;
	forn(0, n, i) {
		char ch;
		int a, b;
		cin >> ch >> a >> b;
		if (ch == 'B')
			buy[a] += b;
		else
			sol[a] += b;
	}
	for (auto & i : buy)
		v1.push_back({ i.first, i.second });
	for (auto & i : sol)
		v2.push_back({ i.first, i.second });
	sort(v1.begin(), v1.end()); reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	for (int i = min((int)v2.size() - 1, s - 1); i >= 0; i--)
		cout << "S" << ' ' << v2[i].first << ' ' << v2[i].second << '\n';
	for (int i = 0; i < v1.size() && i < s; i++)
		cout << "B" << ' ' << v1[i].first << ' ' << v1[i].second << '\n';
}


/*
Sucking Befor Fucking Is The Most Delicious Thing
Sexo
Sexualmente
*/
#include<iostream>
#include<math.h>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<list>
#include<stack>
#include<map>
#include<deque>
#include<string>
#include<set>
#include<unordered_map>
#define IOT ios_base::sync_with_stdio(0);cin.tie(0);
#define Mod 1000000007
#define repi(a,n) for(int i=a;i<n;i++)
#define repj(a,n) for(int j=a;j<n;j++)
#define repk(a,n) for(int k=a;k<n;k++)
#define repe(a,n) for(int i=a;i<=n;i++)
#define TC  ll x; cin>>x; while(x--)
#define ull unsigned long long
#define ll long long
#define ld long double
using namespace std;
ll max(ll a, ll b)
{
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b)
{
	if (a <= b)return a;
	else return b;
}
ll r, c;
bool valid(int i, int j)
{
	if (i >= 0 && i < r && j >= 0 && j < c)return 1;
	else return 0;
}
void yes()
{
	cout << "YES" << endl;
}
void no()
{
	cout << "NO" << endl;
}
/*char** a;
void declare_arr()
{
	a = new char*[r];
	for (int i = 0; i < r; ++i)
		a[i] = new char[c];
	repi(0, r)
	{
		repj(0, c)
		{
			cin >> a[i][j];
		}
	}
}*/
map<ll, vector<ll> >graph;
bool vis[1000005];
bool g = 0; ll smm = 0;
vector<ll>gold;
ll dfs(ll root,ll l)
{
	vis[root] = 1;
	for (auto adj : graph[root])
	{
		if (!vis[adj])
		{
			dfs(adj, l + 1);
		}
	}
	return l;
}
vector<ll>v;
void cin_vec(ll sz)
{
	v.clear();
	repi(0, sz)
	{
		ll h; cin >> h; v.push_back(h);
	}
}
ll smz = 0;
/*ll bs(ll st, ll en)
{
	bool w = 0; ll mn = 1e9 + 1;
	while (st <= en)
	{
		ll mid = (st + en) / 2;
		if (v[mid] != 0 && v[mid] < v[mid + 1]){ mn = v[mid]; en = mid - 1; }
		else if (v[mid] == 0)st = mid + 1;
	}
	return mn;
}*/
void printDivisors(long long n)
{
	v.clear();
	for (int i = 1; i <= sqrt(n); i++)
	{
		if (n%i == 0)
		{
			if (n / i == i)
			{
				v.push_back(i);
			}
			else
			{
				v.push_back(i);
				v.push_back(n / i);
			}
		}
	}
}
map<string, ll>mp;
void subString(string s, ll n)
{
	// Pick starting point in outer loop
	// and lengths of different strings for
	// a given starting point
	for (int i = 0; i < n; i++)
	for (int len = 1; len <= n - i; len++)
		mp[s.substr(i, len)]++;
}
/*bool ispal(string s)
{
	for (int i = 0; i < s.size() / 2; i++)
	if (s[i] != s[s.size() - i - 1]) return false;

	return true;
}*/
bool prime[1000005];
	vector<ll>vp;
void SieveOfEratosthenes()
{
	memset(prime, true, sizeof(prime));
	prime[1] = false;

	for (int p = 2; p * p < 1000005; p++) {
		// If prime[p] is not changed, then it is a prime
		if (prime[p] == true) {
			// Update all multiples of p
			for (int i = p * 2; i < 1000005; i += p)
				prime[i] = false;
		}
	}
	repi(1, 1000005){ if (prime[i])vp.push_back(i); }
}
int gcd(ll a, ll b)
{
	if (!b)return a;
	return gcd(b, a%b);
}
void main()
{
	ll T, R, p, v;
	char ch;
	map<ll, ll>mpS;
	map<ll, ll>mpB;
	map<ll, ll>::reverse_iterator it;
	map<ll, ll>::reverse_iterator it1;
	cin >> T >> R;
	for (int i = 0; i<T; i++)
	{
		cin >> ch >> p >> v;
		if (ch == 'B')mpB[p] += v;
		else if (ch == 'S')mpS[p] += v;
	}
	ll Scnt = 0;
	while (mpS.size()>R)mpS.erase(--mpS.end());
	for (it = mpS.rbegin(); it != mpS.rend(); it++)
	{
		cout << 'S' << " " << it->first << " " << it->second << endl;
	}
	ll Bcnt = 0;
	while (mpB.size()>R)mpB.erase(mpB.begin());
	for (it1 = mpB.rbegin(); it1 != mpB.rend(); it1++)
	{
		cout << 'B' << " " << it1->first << " " << it1->second << endl;
	}
}


#pragma comment(linker, "/STACK:10000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <iomanip>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;
typedef pair<long long, long long> pll;

const double PI = acos(-1.0);
const int INF = 1e9;
const int MOD = INF + 7;
const int BIGINF = 1e16;

char c;
int n, m, q, p;
map <int, ll> mps;
map <int, ll> mpb;
set <ll> b;
set <ll> s;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	double cl = clock();
#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	while (n--) {
		cin >> c >> p >> q;
		if (c == 'S') {
			mps[p] += q;
			s.insert(p);
			if (s.size() > m) s.erase((--s.end()));
		}
		else {
			mpb[p] += q;
			b.insert(p);
			if (b.size() > m) b.erase(b.begin());
		}
	}
	for (int i = 0; i < m; i++) {
		cout << "S " << *(--s.end()) << " " << mps[*(--s.end())] << endl;
		s.erase((--s.end()));
	}
	for (int i = 0; i < m; i++) {
		cout << "B " << *(--b.end()) << " " << mpb[*(--b.end())] << endl;
		b.erase((--b.end()));
	}
#ifdef _DEBUG
	cout << "\n\n" << (clock() - cl) / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


#pragma comment(linker, "/STACK:10000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <iomanip>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;
typedef pair<long long, long long> pll;

const double PI = acos(-1.0);
const int INF = 1e9;
const int MOD = INF + 7;
const int BIGINF = 1e16;

char c;
int n, m, q, p;
map <int, ll> mps;
map <int, ll> mpb;
set <ll> b;
set <ll> s;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	double cl = clock();
#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	while (n--) {
		cin >> c >> p >> q;
		if (c == 'S') {
			mps[p] += q;
			s.insert(p);
			if (s.size() > m) s.erase((--s.end()));
		}
		else {
			mpb[p] += q;
			b.insert(p);
			if (b.size() > m) b.erase(b.begin());
		}
	}
	while (s.size()) {
		cout << "S " << *(--s.end()) << " " << mps[*(--s.end())] << endl;
		s.erase((--s.end()));
	}
	while (b.size()) {
		cout << "B " << *(--b.end()) << " " << mpb[*(--b.end())] << endl;
		b.erase((--b.end()));
	}
#ifdef _DEBUG
	cout << "\n\n" << (clock() - cl) / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


#include <iostream>
#include <map>
#include <functional>
#define ll long long
using namespace std;

int main()
{
	int n, s, p, q, j1 = 0, j2 = 0;
	char d;
	cin >> n >> s;
	map<int, ll>S;
	map<int, ll, greater<ll>>B;
	for (int i = 0; i < n; i++)
	{
		cin >> d >> p >> q;
		if (d == 'S')
			S[p] += q;
		else
			B[p] += q;
	}
	for (auto it = S.begin(); it != S.end() && j1 < s; it++, j1++)
		cout << "S " << it->first << ' ' << it->second << endl;
	for (auto it = B.begin(); it != B.end() && j2 < s; it++, j2++)
		cout << "B " << it->first << ' ' << it->second << endl;
	return 0;
}


#include <iostream>
#include <map>
#include <functional>
#define ll long long
using namespace std;

int main()
{
	int n, s, p, q, j1 = 0, j2 = 0;
	char d;
	cin >> n >> s;
	map<int, ll, greater<ll>>S, B;
	for (int i = 0; i < n; i++)
	{
		cin >> d >> p >> q;
		if (d == 'S')
			S[p] += q;
		else
			B[p] += q;
	}
	for (auto it = S.begin(); it != S.end() && j1 < s; it++, j1++)
		cout << "S " << it->first << ' ' << it->second << endl;
	for (auto it = B.begin(); it != B.end() && j2 < s; it++, j2++)
		cout << "B " << it->first << ' ' << it->second << endl;
	return 0;
}


#include <iostream>
#include <map>
#include <functional>
#define ll long long
using namespace std;

int main()
{
	int n, s, p, q, j1 = 0, j2 = 0;
	char d;
	cin >> n >> s;
	map<int, ll>S;
	map<int, ll, greater<ll>>B, Sans;
	for (int i = 0; i < n; i++)
	{
		cin >> d >> p >> q;
		if (d == 'S')
			S[p] += q;
		else
			B[p] += q;
	}
	for (auto it = S.begin(); it != S.end() && j1 < s; it++, j1++)
		Sans[it->first] = it->second;
	for (auto it = Sans.begin(); it != Sans.end(); it++)
		cout << "S " << it->first << ' ' << it->second << endl;
	for (auto it = B.begin(); it != B.end() && j2 < s; it++, j2++)
		cout << "B " << it->first << ' ' << it->second << endl;
	return 0;
}


#include <iostream>
#include <map>
#define ll long long
using namespace std;

int main()
{
	int n, s, p, q, j1 = 0, j2 = 0;
	char d;
	cin >> n >> s;
	map<int, ll, greater<ll>>S, B;
	for (int i = 0; i < n; i++)
	{
		cin >> d >> p >> q;
		if (d == 'S')
			S[p] += q;
		else
			B[p] += q;
	}
	for (auto it = S.begin(); it != S.end() && j1 < s; it++, j1++)
		cout << "S " << it->first << ' ' << it->second << endl;
	for (auto it = B.begin(); it != B.end() && j2 < s; it++, j2++)
		cout << "B " << it->first << ' ' << it->second << endl;
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdio>
using namespace std;
struct order {
	int price;
	int num;
	order(int a, int b) :price(a), num(b) {};
	order() = default;
};
void combine(list<order> &p);
int s;
int main()
{
	char ch;
	int n, a, b;
	cin >> n>>s;
	vector<order>buyy, selll;
	for (int i = 0; i != n; ++i) {
		cin >> ch >> a >> b;
		if (ch == 'B')buyy.emplace_back(a, b);
		else selll.emplace_back(a, b);
	}
	list<order>buy(buyy.begin(), buyy.end()), sell(selll.begin(), selll.end());
	buy.sort([](order a, order b) {return a.price > b.price; });
	//sort(buy.begin(), buy.end(), [](order a, order b) {return a.price > b.price; });
	sell.sort([](order a, order b) {return a.price < b.price; });
	//sort(sell.begin(), sell.end(), [](order a, order b) {return a.price < b.price; });
	combine(buy); combine(sell);
	sell.sort([](order a, order b) {return a.price > b.price; });
	//sort(sell.begin(), sell.end(), [](order a, order b) {return a.price > b.price; });
	//cout << "--------------------------------------------------------------------------------------------------";
	for (auto &i : sell) {
		cout << "S " << i.price << " " << i.num << endl;
	}
	for (auto &i : buy) {
		cout << "B " << i.price << " " << i.num << endl;
	}
	return 0;
}
void combine(list<order> &p) {
	for (auto acc = p.begin(); acc != p.end(); ++acc) {
		auto nn = acc;
		++nn;
		if (nn != p.end()) {
			while (nn!=p.end()&&(*nn).price == (*acc).price) {
				(*acc).num += (*nn).num;
				nn=p.erase(nn);
			}
		}
	}
	if (s < p.size()) {
		auto acc = p.begin();
		for (int i = 0; i != s; ++i) ++acc;
		p.erase(acc, p.end());
	}
}


#include <iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdio>
using namespace std;
struct order {
	int num;
	int price;
	order(int a, int b) :price(a), num(b) {};
	order() = default;
};
void combine(list<order> &p);
int s;
int main()
{
	char ch;
	int n, a, b;
	cin >> n>>s;
	vector<order>buyy, selll;
	for (int i = 0; i != n; ++i) {
		cin >> ch >> a >> b;
		if (ch == 'B')buyy.emplace_back(a, b);
		else selll.emplace_back(a, b);
	}
	list<order>buy(buyy.begin(), buyy.end()), sell(selll.begin(), selll.end());
	buy.sort([](order a, order b) {return a.price > b.price; });
	//sort(buy.begin(), buy.end(), [](order a, order b) {return a.price > b.price; });
	sell.sort([](order a, order b) {return a.price < b.price; });
	//sort(sell.begin(), sell.end(), [](order a, order b) {return a.price < b.price; });
	combine(buy); combine(sell);
	sell.sort([](order a, order b) {return a.price > b.price; });
	//sort(sell.begin(), sell.end(), [](order a, order b) {return a.price > b.price; });
	for (auto &i : sell) {
		cout << "S " << i.price << " " << i.num << endl;
	}
	for (auto &i : buy) {
		cout << "B " << i.price << " " << i.num << endl;
	}
	return 0;
}
void combine(list<order> &p) {
	for (auto acc = p.begin(); acc != p.end(); ++acc) {
		auto nn = acc;
		++nn;
		if (nn != p.end()) {
			if ((*nn).price == (*acc).price) {
				(*acc).num += (*nn).num;
				p.erase(nn);
			}
		}
	}
	if (s < p.size()) {
		auto acc = p.begin();
		for (int i = 0; i != s; ++i) ++acc;
		p.erase(acc, p.end());
	}
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());

	int k = 0;
	int count_s = n - count;
	int p = 0;
	unsigned  i = n - 1;
	while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}
	i = count - 1; k = 0; p = 0;
	while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}

	/*if (n <= s)
	{
		for(unsigned q=n;q>0;--q)
			cout << zap[q-1].first << " " << zap[q-1].second.first << " " << zap[q-1].second.second << endl;
		return 0;
		//unsigned q = n - 1;
		//while (q !=0)
		//{
		//	cout << zap[q].first << " " << zap[q].second.first << " " << zap[q].second.second << endl;
		//}
		//cout << zap[0].first << " " << zap[0].second.first << " " << zap[0].second.second << endl;
		//return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i> 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i > 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	if (n <= s)
	{
		for(unsigned q=n;q>0;--q)
			cout << zap[q-1].first << " " << zap[q-1].second.first << " " << zap[q-1].second.second << endl;
		return 0;
		//unsigned q = n - 1;
		//while (q !=0)
		//{
		//	cout << zap[q].first << " " << zap[q].second.first << " " << zap[q].second.second << endl;
		//}
		//cout << zap[0].first << " " << zap[0].second.first << " " << zap[0].second.second << endl;
		//return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i> 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i > 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	if(n<=s)
		for (unsigned p = n-1;  p>=0; --p)
		{
			cout << zap[p].first << " " << zap[p].second.first << " " << zap[p].second.second << endl;
			return 0;
		}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	if (n <= s)
	{
		for (unsigned p = n - 1; p >= 0; --p)
			cout << zap[p].first << " " << zap[p].second.first << " " << zap[p].second.second << endl;
		return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>
#include <map>
using namespace std;

int main()
{
	int n, s, tem, tep;
	char c;
	cin >> n >> s;
	int count_b = 0, count_s=0;
	//map<int, int> zap;
	vector <pair<int, int>> zap;
	int j = 1;
	//map<int, int> ::iterator it;
	vector<pair< int, int>> ::iterator it2=zap.begin();
	//cin >> c >> tem >> tep;
	//zap[0].first = tem;
	//zap[0].second = tep;
	for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;
			const int key = tem;
			auto it = find_if(zap.begin(), zap.end(), [&key](const auto &p) { return p.first == key; });
			if (it == zap.end())
			{
				zap.push_back(make_pair(tem, tep));
				if (c == 'B')
					++count_b;
				else
					++count_s;
				++j;
			}
			else
			{
				it->second = it->second + tep;
			}
	}
	sort(zap.begin(), zap.end());
	if (count_s <= s)
		for (int i = count_b+count_s-1; i > count_b-1; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b +s-1; i > count_b-1 ; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	if (count_b <=s)
		for (int i = count_b-1 ; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b-1; i > count_b -s-1; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;

	/*for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;

		it = zap.find(tem);
		if (it == zap.end())
		{
			//zap[tem] = tep;
			zap.insert(make_pair(tem, tep));
			if (c == 'B')
				++count_b;
			else
				++count_s;
		}
		else
			it->second += tep;
	}

	if (count_s <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s+1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}
	if (count_b <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s + 1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}

		/*for(int i=count_b+s-1;i>=count_b;--i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second;
	if (count_b < s)
		for (int i = count_b - 1; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;
	else
		for (int i = count_b - 1; i >= count_b-s; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;

	/*int k = 0;
	int count_s = n - count;
	int p = 0;
	unsigned  i = n - 1;
	while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}
	i = count - 1; k = 0; p = 0;
	while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}

	/*if (n <= s)
	{
		for(unsigned q=n;q>0;--q)
			cout << zap[q-1].first << " " << zap[q-1].second.first << " " << zap[q-1].second.second << endl;
		return 0;
		//unsigned q = n - 1;
		//while (q !=0)
		//{
		//	cout << zap[q].first << " " << zap[q].second.first << " " << zap[q].second.second << endl;
		//}
		//cout << zap[0].first << " " << zap[0].second.first << " " << zap[0].second.second << endl;
		//return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i> 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i > 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>
#include <map>
using namespace std;

int main()
{
	int n, s, tem, tep;
	char c;
	cin >> n >> s;
	int count_b = 0, count_s=0;
	//map<int, int> zap;
	vector <pair<int, int>> zap (n);
	int j = 0;
	//map<int, int> ::iterator it;
	vector<pair< int, int>> ::iterator it2=zap.begin();
	for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;
		const int key = tem;
		auto it = find_if(zap.begin(), zap.end(), [&key](const auto &p) { return p.first == key; });
		if (it == zap.end())
		{
			zap[j].first = tem;
			zap[j].second = tep;
			if (c == 'B')
				++count_b;
			else
				++count_s;
			++j;
		}
		else
		{
			it->second = it->second + tep;
		}
	}
	zap.resize(j);
	sort(zap.begin(), zap.end());
	if (count_s <= s)
		for (int i = count_b+count_s-1; i > count_b-1; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b +s-1; i > count_b-1 ; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	if (count_b <=s)
		for (int i = count_b-1 ; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b-1; i > count_b -s-1; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;

	/*for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;

		it = zap.find(tem);
		if (it == zap.end())
		{
			//zap[tem] = tep;
			zap.insert(make_pair(tem, tep));
			if (c == 'B')
				++count_b;
			else
				++count_s;
		}
		else
			it->second += tep;
	}

	if (count_s <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s+1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}
	if (count_b <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s + 1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}

		/*for(int i=count_b+s-1;i>=count_b;--i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second;
	if (count_b < s)
		for (int i = count_b - 1; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;
	else
		for (int i = count_b - 1; i >= count_b-s; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;

	/*int k = 0;
	int count_s = n - count;
	int p = 0;
	unsigned  i = n - 1;
	while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}
	i = count - 1; k = 0; p = 0;
	while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}

	/*if (n <= s)
	{
		for(unsigned q=n;q>0;--q)
			cout << zap[q-1].first << " " << zap[q-1].second.first << " " << zap[q-1].second.second << endl;
		return 0;
		//unsigned q = n - 1;
		//while (q !=0)
		//{
		//	cout << zap[q].first << " " << zap[q].second.first << " " << zap[q].second.second << endl;
		//}
		//cout << zap[0].first << " " << zap[0].second.first << " " << zap[0].second.second << endl;
		//return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i> 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i > 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>
#include <map>
using namespace std;

int main()
{
	int n, s, tem, tep;
	char c;
	cin >> n >> s;
	int count_b = 0, count_s=0;
	//map<int, int> zap;
	vector <pair<int, int>> zap (n);
	int j = 0;
	//map<int, int> ::iterator it;
	vector<pair< int, int>> ::iterator it2=zap.begin();
	for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;
		if (tem != 0)
		{
			const int key = tem;
			auto it = find_if(zap.begin(), zap.end(), [&key](const auto &p) { return p.first == key; });
			if (it == zap.end())
			{
				zap[j].first = tem;
				zap[j].second = tep;
				if (c == 'B')
					++count_b;
				else
					++count_s;
				++j;
			}
			else
			{
				it->second = it->second + tep;
			}
		}
	}
	zap.resize(j);
	sort(zap.begin(), zap.end());
	if (count_s <= s)
		for (int i = count_b+count_s-1; i > count_b-1; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b +s-1; i > count_b-1 ; --i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second<<endl;
	if (count_b <=s)
		for (int i = count_b-1 ; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;
	else
		for (int i = count_b-1; i > count_b -s-1; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second<<endl;

	/*for (int i = 0; i < n; ++i)
	{
		cin >> c >> tem >> tep;

		it = zap.find(tem);
		if (it == zap.end())
		{
			//zap[tem] = tep;
			zap.insert(make_pair(tem, tep));
			if (c == 'B')
				++count_b;
			else
				++count_s;
		}
		else
			it->second += tep;
	}

	if (count_s <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s+1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}
	if (count_b <= s)
	{
		it = zap.end();
		it--;
		for (int i = 0; i < count_s; ++i)
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}

	}
	else
	{
		int i = 0;
		it = zap.end();
		advance(it, s + 1);
		while (it != zap.end())
		{
			cout << "S" << " " << it->first << " " << it->second;
			--it;
		}
	}

		/*for(int i=count_b+s-1;i>=count_b;--i)
			cout << "S" << " " << zap[i].first << " " << zap[i].second;
	if (count_b < s)
		for (int i = count_b - 1; i >= 0; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;
	else
		for (int i = count_b - 1; i >= count_b-s; --i)
			cout << "B" << " " << zap[i].first << " " << zap[i].second;

	/*int k = 0;
	int count_s = n - count;
	int p = 0;
	unsigned  i = n - 1;
	while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}
	i = count - 1; k = 0; p = 0;
	while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		while (i > 0 && zap[i].second.first == zap[i - 1].second.first)
		{
			zap[i - 1].second.second += zap[i].second.second;
			--i;
			++p;
		}
		cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
		--i;
		++k;
		++p;
	}

	/*if (n <= s)
	{
		for(unsigned q=n;q>0;--q)
			cout << zap[q-1].first << " " << zap[q-1].second.first << " " << zap[q-1].second.second << endl;
		return 0;
		//unsigned q = n - 1;
		//while (q !=0)
		//{
		//	cout << zap[q].first << " " << zap[q].second.first << " " << zap[q].second.second << endl;
		//}
		//cout << zap[0].first << " " << zap[0].second.first << " " << zap[0].second.second << endl;
		//return 0;
	}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i> 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (i > 0&&zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	int k = 0;
	unsigned  i = n - 1;
	while (k < s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout<< zap[i].first <<" "<< zap[i].second.first <<" "<< zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			//--i;
			//++k;
		//}
	}
	i = count - 1; k = 0;
	while (k < s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			//--i;
			//++k;
		//}
	}

	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	if(n<=s)
		for (int i = 0; i < n; ++i)
		{
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			return 0;
		}
	else
	{

		int k = 0;
		int count_s = n - count;
		int p = 0;
		unsigned  i = n - 1;
		while (k < s&&p < count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}
		i = count - 1; k = 0; p = 0;
		while (k < s&&p < count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
		{
			//if (zap[i].second.first == zap[i - 1].second.first)
			//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
				++p;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
			++p;
			//}
			//else
			//{
				//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
				//--i;
				//++k;
			//}
		}

	}
	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	int k = 0;
	unsigned  i = n - 1;
	while (k < s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout<< zap[i].first <<" "<< zap[i].second.first <<" "<< zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			//--i;
			//++k;
		//}
	}
	i = count - 1; k = 0;
	while (k < s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
		//}
	}

	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string.>
#include<vector>

using namespace std;

int main()
{
	int n, s;
	cin >> n >> s;
	vector <pair<char, pair<int, int>>> zap(n);
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> zap[i].first >> zap[i].second.first >> zap[i].second.second;
		if (zap[i].first == 'B')
			++count;
	}
	std::sort(zap.begin(), zap.end());
	int k = 0;
	int count_s = n - count;
	int p = 0;
	unsigned  i = n - 1;
	while (k < s&&p<count_s)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout<< zap[i].first <<" "<< zap[i].second.first <<" "<< zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			//--i;
			//++k;
		//}
	}
	i = count - 1; k = 0; p = 0;
	while (k < s&&p<count)// для продаж, если гарантировано, что эс больше количества агрегированных продаж
	{
		//if (zap[i].second.first == zap[i - 1].second.first)
		//{
			while (zap[i].second.first == zap[i - 1].second.first)
			{
				zap[i - 1].second.second += zap[i].second.second;
				--i;
			}
			cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			--i;
			++k;
		//}
		//else
		//{
			//cout << zap[i].first << " " << zap[i].second.first << " " << zap[i].second.second << endl;
			//--i;
			//++k;
		//}
	}

	/*int n, m, k_ob=0, k_en=0;
	cin >> n>> m;
	vector<string> pol (n);
	string s;

	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		pol.push_back(s);
	}

	for (int i = 0; i < m; ++i)
	{
		cin >> s;
		if (find(pol.begin(), pol.end(), s)!=pol.end())
			++k_ob;
		++k_en;
	}

	if (m - k_ob == n - k_ob)
		if (k_ob % 2 == 0)
			if (n <= m)
			{
				cout << "NO" << endl;
				return 0;
			}
			else
			{
				cout << "YES" << endl;
				return 0;
			}
		else
		{
			cout << "YES";
			return 0;
		}
	if (k_en - k_ob > n - k_ob)
		cout << "NO" << endl;
	else
		if (k_en < k_ob < n - k_ob)
			cout << "YES";

	int t, n;
	cin >> t;
	int * col = new int[t];
	int need_gr, tek_gr;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		int * a = new int[n];
		for (int j = 0; j < n; ++j)
			cin >> a[j];
		sort(a, a + n);
		col[i] = 0;
		int j = 0;
		need_gr = a[j];
		tek_gr = 1;
		while (j < n) // n-1
		{
			if (need_gr == tek_gr)
			{
				col[i]+=1;
				need_gr = a[j+1];
				tek_gr = 1;
			}
			else
			{
				if (a[j]!= a[j + 1])
					need_gr = a[j + 1];
				++tek_gr;
			}
			++j;
		}

		delete[] a;
	}
	for (int i = 0; i < t; ++i)
		cout << col[i] << endl;

	delete[] col;*/
}


#pragma comment(linker, "/STACK:10000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#define rt return
#define rt0 return 0
#define rt1 return 1
#define mp make_pair
#define endl "\n"
#define cen cout << "\n"
#define all(x) begin(x), end(x)
#define rep(x) for (int rep_iter = 0; rep_iter < x; ++rep_iter)
#define fnd(x, y) (x.find(y) != x.end())
#define fndv(x, y) (find(all(x), y) != end(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
typedef unsigned char bt;
typedef unsigned int uint;
const int MOD = 1000000007;
const int INF = 1000000007;
const ll INF2 = 1000000007LL * 1000000007LL;
const long double EPS = 1e-9;
#ifdef _DEBUG
const int SIZE = 100;
#endif
#ifndef _DEBUG
const int SIZE = 200100; //200010
#endif

map<int, int> s, b;

int main() {
#ifdef _DEBUG
//#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	rep(n) {
		char d;
		int p, q;
		cin >> d >> p >> q;
		if (d == 'S') {
			s[p] += q;
		}
		else {
			b[-p] += q;
		}
	}
	while (s.size() > k)
		s.erase(--s.end());
	for (auto i = s.rbegin(); i != s.rend(); ++i) {
		cout << "S " << i->first << " " << i->second << endl;
	}
	while (b.size() > k)
		b.erase(--b.end());
	for (auto i = b.begin(); i != b.end(); ++i) {
		cout << "B " << -i->first << " " << i->second << endl;
	}

	return 0;
}


#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

typedef long long ll;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n, s, k , m;

	const int count = 100001;

	double EPS = 1E-9;

	ll a[count];
	ll b[count];

	while(cin >> n >> s  )
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0; i< n; i++)
		{
			string order ;
			int p , q;
			cin >> order >> p >> q;
			if(order == "B")
				b[p] += q;
			if(order == "S")
				a[p] += q;
		}
		int t = 0;
		for(int i = count-1; t < s && t < n && i >=0; i--)
		{
			if(a[i] > 0)
			{
				printf("S %i %i \n",i, a[i]);t++;
			}
		}
		t = 0;
		for(int i=0; t < s && t < n && i < count ; i++)
		{
			if(b[i] > 0)
			{
				printf("B %i %i \n",i, b[i]);t++;
			}
		}
	}
#ifndef ONLINE_JUDGE
	system("pause");
#endif

	return 0;
}


#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

typedef long long ll;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n, s, k , m;

	const int count = 100001;

	double EPS = 1E-9;

	ll a[count];
	ll b[count];

	while(cin >> n >> s  )
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0; i< n; i++)
		{
			string order ;
			int p , q;
			cin >> order >> p >> q;
			if(order == "B")
				b[p] += q;
			if(order == "S")
				a[p] += q;
		}
		int t = 0;
		for(int i=0; t < s && t < n && i < count ; i++)
		{
			if(a[i] > 0)
			{
				printf("S %i %i \n",i, a[i]);t++;
			}
		}
		t = 0;
		for(int i = count-1; t < s && t < n && i >=0; i--)
		{
			if(b[i] > 0)
			{
				printf("B %i %i \n",i, b[i]);t++;
			}
		}
	}
#ifndef ONLINE_JUDGE
	system("pause");
#endif

	return 0;
}


#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

typedef long long ll;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n, s, k , m;

	const int count = 100001;

	double EPS = 1E-9;

	ll a[count];
	ll b[count];

	while(cin >> n >> s  )
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0; i< n; i++)
		{
			string order ;
			int p , q;
			cin >> order >> p >> q;
			if(order == "B")
				b[p] += q;
			if(order == "S")
				a[p] += q;
		}
		int t = 0;
		vector<ll> buy;
		vector<int>qs;
		for(int i = 0; t < s && i < count; i++)
		{
			if(a[i] > 0)
			{
				//printf("B %i %i \n",i, b[i]);t++;
				qs.push_back(i);
				buy.push_back(a[i]);t++;
			}
		}
		for(int i = buy.size()-1; i >=0; i--)
		{
			printf("S %i %i \n",qs.at(i), buy.at(i) );t++;
		}
		t = 0;
		for(int i = count-1; t < s && t < n && i >=0; i--)
		{
			if(b[i] > 0)
			{
				printf("B %i %i \n",i, b[i]);t++;
			}
		}

	}
#ifndef ONLINE_JUDGE
	system("pause");
#endif

	return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

int dx[]={ 0 , 0 , -1 , 1 },dy[]={ -1 , 1 , 0 , 0};
//int dx[] = { -1, -1, 1, 1, -2, -2, 2, 2 };
//int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

  int x,y;
  scanf("%d%d", &x,&y);

  map<pair<int,char> , int> myBook;
  map<pair<int,char> , int>::iterator it = myBook.begin();

  while(x--){

      int a,b;
      char cc;
      scanf(" %c %d%d" , &cc , &a,&b);

      myBook[make_pair(a,cc)] +=b;

  }

  int temp = y;
  for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
      if(temp){
        if(it->first.second == 'S')
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

  temp = y;
  for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
      if(temp){
        if(it->first.second == 'B')
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

return 0;}


#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

int dx[]={ 0 , 0 , -1 , 1 },dy[]={ -1 , 1 , 0 , 0};
//int dx[] = { -1, -1, 1, 1, -2, -2, 2, 2 };
//int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

  int x,y;
  scanf("%d%d", &x,&y);

  map<pair<int,char> , int> myBook , temp_map;
  map<pair<int,char> , int>::iterator it = myBook.begin();

  while(x--){

      int a,b;
      char cc;
      scanf(" %c %d%d" , &cc , &a,&b);

      myBook[make_pair(a,cc)] +=b;

  }

  int temp = y;
  for ((it = myBook.begin()); it != (myBook.end()); it++)
  {
      if(temp){
        if(it->first.second == 'S')
            temp_map[make_pair(it->first.first ,it->first.second )]= it->second , temp--;
         // cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

   temp = y;
   if(temp_map.size() > 0)
   for ((it = (temp_map.end()))--; it != --(temp_map.begin()); it--)
  {
        if(temp){
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl;
          temp--;
        }
    }

  temp = y;
  for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
      if(temp){
        if(it->first.second == 'B')
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

return 0;}


#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

int dx[]={ 0 , 0 , -1 , 1 },dy[]={ -1 , 1 , 0 , 0};
//int dx[] = { -1, -1, 1, 1, -2, -2, 2, 2 };
//int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

  int x,y;
  scanf("%d%d", &x,&y);

  map<pair<int,char> , int> myBook , temp_map;
  map<pair<int,char> , int>::iterator it = myBook.begin();

  while(x--){

      int a,b;
      char cc;
      scanf(" %c %d%d" , &cc , &a,&b);

      myBook[make_pair(a,cc)] +=b;

  }

  int temp = y;
  for ((it = myBook.begin()); it != (myBook.end()); it++)
  {
      if(temp){
        if(it->first.second == 'S')
            temp_map[make_pair(it->first.first ,it->first.second )]= it->second;
         // cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

   temp = y;
   if(temp_map.size() > 0)
   for ((it = temp_map.end())--; it != --(temp_map.begin()); it--)
  {
        if(temp){
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl;
          temp--;
        }
    }

  temp = y;
  for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
      if(temp){
        if(it->first.second == 'B')
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

return 0;}


#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

int dx[]={ 0 , 0 , -1 , 1 },dy[]={ -1 , 1 , 0 , 0};
//int dx[] = { -1, -1, 1, 1, -2, -2, 2, 2 };
//int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

  int x,y;
  scanf("%d%d", &x,&y);

  map<pair<int,char> , int> myBook , temp_map;
  map<pair<int,char> , int>::iterator it = myBook.begin();

  while(x--){

      int a,b;
      char cc;
      scanf(" %c %d%d" , &cc , &a,&b);

      myBook[make_pair(a,cc)] +=b;

  }

  int temp = y;
  for ((it = myBook.begin()); it != (myBook.end()); it++)
  {
      if(temp){
        if(it->first.second == 'S')
            temp_map[make_pair(it->first.first ,it->first.second )]= it->second;
         // cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

   temp = y;
   for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
        if(temp){
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl;
          temp--;
        }
    }

  temp = y;
  for ((it = myBook.end())--; it != --(myBook.begin()); it--)
  {
      if(temp){
        if(it->first.second == 'B')
          cout<< (it->first.second)<<" "<<it->first.first<<" "<<it->second<<endl , temp--;

      }
      else
      {
          break;
      }
  }

return 0;}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;
		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff * temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							temp->prev = newElem;
							bHead = newElem;
						}
						else
						{
							temp->prev = newElem;
							temp = temp->prev;
							temp->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
							temp->prev = newElem;
						}
						else
						{
							temp->prev = newElem;
							temp = temp->prev;
							temp->next = newElem;;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp = sHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "S " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;
		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff *temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							temp->prev = newElem;
							bHead = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
							temp->prev = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp2 = sHead;
	while (temp2 != NULL && temp2->next != NULL)
		temp2 = temp2->next;

	for (int i = 1; i < s; i++)
	{
		if (temp2 == NULL || temp2->prev == NULL)
			break;

		temp2 = temp2->prev;
	}

	while (temp2 != NULL)
	{
		cout << "S " << temp2->priece << " " << temp2->count << endl;
		temp2 = temp2->next;
	}

	fff *temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;
		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff * temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							temp->prev = newElem;
							bHead = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
							temp->prev = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp = sHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "S " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;
		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff *temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							temp->prev = newElem;
							bHead = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
							temp->prev = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp2 = sHead;
	while (temp2->next != NULL)
		temp2 = temp2->next;

	for (int i = 1; i < s; i++)
	{
		if (temp2 == NULL || temp2->prev == NULL)
			break;

		temp2 = temp2->prev;
	}

	while (temp2 != NULL)
	{
		cout << "S " << temp2->priece << " " << temp2->count << endl;
		temp2 = temp2->next;
	}

	fff *temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;

		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff * temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							bHead = newElem;
						}
						else
						{
							temp->prev->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
						}
						else
						{
							temp->prev->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp = sHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "S " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}

	return 0;
}


#include <iostream>
using namespace std;

struct fff
{
	int priece;
	int count;

	fff *next;
	fff *prev;
};

fff *sHead = NULL, *bHead = NULL;

int main()
{
	int s, n;
	cin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		char ch;
		int priece, num;
		cin >> ch >> priece >> num;

		if (ch == 'B')
		{
			if (bHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				bHead = newElem;
			}
			else
			{
				for (fff *temp = bHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							temp->prev = newElem;
							bHead = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
		else
		{
			if (sHead == NULL)
			{
				fff *newElem = new fff;
				newElem->priece = priece;
				newElem->count = num;
				newElem->next = NULL;
				newElem->prev = NULL;
				sHead = newElem;
			}
			else
			{
				for (fff * temp = sHead; temp != NULL; temp = temp->next)
				{
					if (temp->priece == priece)
					{
						temp->count += num;
						break;
					}
					else if (temp->priece < priece)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = temp;
						newElem->prev = temp->prev;
						if (temp->prev == NULL)
						{
							sHead = newElem;
							temp->prev = newElem;
						}
						else
						{
							fff *temp2 = temp->prev;
							temp->prev = newElem;
							temp2->next = newElem;
						}
						break;
					}
					if (temp->next == NULL)
					{
						fff *newElem = new fff;
						newElem->priece = priece;
						newElem->count = num;
						newElem->next = NULL;
						newElem->prev = temp;
						temp->next = newElem;
						break;
					}
				}
			}
		}
	}
	fff *temp2 = sHead;
	while (temp2 != NULL || temp2->next != NULL)
		temp2 = temp2->next;

	for (int i = 1; i < s; i++)
	{
		if (temp2 == NULL || temp2->prev == NULL)
			break;

		temp2 = temp2->prev;
	}

	while (temp2 != NULL)
	{
		cout << "S " << temp2->priece << " " << temp2->count << endl;
		temp2 = temp2->next;
	}

	fff *temp = bHead;
	for (int i = 0; i < s; i++)
	{
		if (temp == NULL)
			break;

		cout << "B " << temp->priece << " " << temp->count << endl;
		temp = temp->next;
	}
	return 0;
}


#include<iostream>
#include<functional>
#include<map>
using namespace std;
#define mii map<int,int,greater<int>>
mii buy, sell;
mii::iterator it;
int main()
{
	int n, s, p, q;
	char d;
	cin >> n >> s;
	for (int i = 0; i < n; ++i)
	{
		cin >> d >> p >> q;
		if (d == 'B')
			buy[p] += q;
		else
			sell[p] += q;
	}
	int s1 = 0, s2 = 0;
	for (it = sell.begin(); it != sell.end() && s1 < s; ++it, ++s1)
		cout << 'S' << " " << it->first << " " << it->second << endl;
	for (it = buy.begin(); it != buy.end() && s2 < s; ++it, ++s2)
		cout << 'B' << " " << it->first << " " << it->second << endl;
	return 0;
}


#include<iostream>
#include<functional>
#include<map>
using namespace std;
#define mii map<int,int,greater<int>>
mii buy, sell;
mii::iterator it;
int main()
{
	int n, s, p, q;
	char d;
	cin >> n >> s;
	for (int i = 0; i < n; ++i)
	{
		cin >> d >> p >> q;
		if (d == 'B')
			buy[p] += q;
		else
			sell[p] += q;
	}
	int s1 = 0, s2 = 0;
	if (sell.size() > s)
	{
		for (it = next(sell.begin(), sell.size()-s-1); it != sell.end() && s1 < s; ++it, ++s1)
			cout << 'S' << " " << it->first << " " << it->second << endl;
	}
	else {
		for (it = sell.begin(); it != sell.end() && s1 < s; ++it, ++s1)
			cout << 'S' << " " << it->first << " " << it->second << endl;
	}
	for (it = buy.begin(); it != buy.end() && s2 < s; ++it, ++s2)
		cout << 'B' << " " << it->first << " " << it->second << endl;
	return 0;
}


#include<iostream>
#include<functional>
#include<map>
using namespace std;
#define mii map<int,int,greater<int>>
mii buy, sell;
mii::iterator it;
int main()
{
	int n, s, p, q;
	char d;
	cin >> n >> s;
	for (int i = 0; i < n; ++i)
	{
		cin >> d >> p >> q;
		if (d == 'B')
			buy[p] += q;
		else
			sell[p] += q;
	}
	int s1 = 0, s2 = 0;
	if (sell.size() > s)
	{
		for (it = next(sell.begin(), sell.size()-s); it != sell.end() && s1 < s; ++it, ++s1)
			cout << 'S' << " " << it->first << " " << it->second << endl;
	}
	else {
		for (it = sell.begin(); it != sell.end() && s1 < s; ++it, ++s1)
			cout << 'S' << " " << it->first << " " << it->second << endl;
	}
	for (it = buy.begin(); it != buy.end() && s2 < s; ++it, ++s2)
		cout << 'B' << " " << it->first << " " << it->second << endl;
	return 0;
}


#include <iostream>

using namespace std;

int buy[100007];
int sell[100007];
int sellout[100007];
int main()
{
    freopen("in.txt", "r", stdin);
    int n, s;
    cin >> n >> s;
    char d;
    int p, q;
    for(int i = 0; i < n; i++)
    {
        cin >> d >> p >> q;
        if(d == 'B')
            buy[p] += q;
        else
            sell[p] += q;
    }
    int sellnum = s;
    for(int i = 0; i <= 1e5 && sellnum; i++)
        if(sell[i])
        {
            sellout[i] = sell[i];
            sellnum--;
        }
    for(int i = 1e5; i >= 0; i--)
        if(sell[i])
            cout << "S " << i << ' ' << sell[i] << endl;
    int buynum = s;
    for(int i = 1e5; i >= 0 && buynum; i--)
        if(buy[i])
        {
            cout << "B " << i << ' ' << buy[i] << endl;
            buynum--;
        }
    return 0;
}