#include <bits/stdc++.h>
using namespace std;
vector<long long int> g[10];
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int sum(long long int n) {
  int s = 0;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int test = 1;
long long int indexlow(long long int ar[], long long int n, long long int t) {
  long long int res = 0;
  long long int low = 0;
  long long int high = n - 1;
  long long int mid = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ar[mid] > t) {
      high = mid - 1;
    } else if (ar[mid] < t) {
      low = mid + 1;
    } else
      high = mid - 1;
  }
  return low + 1;
}
long long int indexhigh(long long int ar[], long long int n, long long int t) {
  long long int res = 0;
  long long int low = 0;
  long long int high = n - 1;
  long long int mid = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ar[mid] > t) {
      high = mid - 1;
    } else if (ar[mid] <= t) {
      low = mid + 1;
    }
  }
  return low + 1;
}
double find_sqrt_step1(long long int x) {
  long long int low = 1, high = x;
  long long int mid;
  double ans;
  while (low < high) {
    mid = (low + high) / 2;
    if (mid * mid == x) {
      ans = mid;
      break;
    } else if (mid * mid < x) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  double tem = 0.1;
  for (int i = 1; i <= 10; i++) {
    while (ans * ans < x) {
      ans += tem;
    }
    ans -= tem;
    tem = tem / 10;
  }
  return ans;
}
double find_sqrt_step2(long long int x) {
  double low = 1, high = x, ans, mid, abs = 1e-10;
  while (high - low > abs) {
    mid = (low + high) / 2;
    if (mid * mid > x) {
      high = mid;
    } else {
      low = mid;
    }
  }
  return mid;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.first < b.first;
  }
  return false;
}
long long int pro(long long int a) {
  long long int p = 1;
  if (a < 10) return a;
  while (a > 0) {
    if (a % 10) p *= a % 10;
    a /= 10;
  }
  return pro(p);
}
void pre() {
  for (long long int i = 1; i <= 1000000; i++) {
    long long int t = pro(i);
    g[t].push_back(i);
  }
}
int t[10][1000005];
void solve() {
  long long int n, k;
  cin >> n >> k;
  map<long long int, long long int> S;
  map<long long int, long long int, greater<long long int>> B;
  long long int a, b;
  char c;
  while (n--) {
    cin >> c >> a >> b;
    if (c == 'S')
      S[a] += b;
    else
      B[a] += b;
  }
  long long int i = 1;
  long long int p = S.size();
  long long int t = min(p, k);
  vector<int> vec;
  for (auto a : S) {
    vec.push_back(a.first);
    if (i == t) break;
    i++;
  }
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    cout << "S"
         << " " << vec[i] << " " << S[vec[i]] << '\n';
  }
  i = 1;
  p = B.size();
  t = min(p, k);
  for (auto a : B) {
    cout << "B"
         << " ";
    cout << a.first << " " << a.second << '\n';
    if (i == t) break;
    i++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
