#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_int_update
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_int_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int
const int MAXN = (int)1e6 + 10;
const int MOD = 1000000007;
int K, n;
int tree[4 * MAXN];
void build(int id, int tl, int tr){
if(tl > tr){
return;
}
if( tl == tr ){
tree[id] = K;
return;
}
int tm = (tl + tr) / 2;
build(id * 2, tl, tm);
build(id * 2 + 1, tm + 1, tr);
tree[id] = tree[id * 2] + tree[id * 2 + 1];
}
void update(int id, int tl, int tr, int val){
if(tl > tr){
return;
}
if( tl == tr ){
tree[id] -= val;
return;
}
//check if we can go left side
int tm = (tl + tr) / 2;
if(tree[id * 2] >= val){
update(id * 2, tl, tm, val);
} else if( tree[id * 2 + 1] >= val ){
update(id * 2 + 1, tm + 1, tr, val);
}
//after updation change its parent
tree[id] = tree[id * 2] + tree[id * 2 + 1];
}
int res = 0, used = 0;
void get_ans(int id, int tl, int tr){
if( tl > tr ){
return;
}
if(tl == tr){
if(tree[id] < K)
res += tree[id], used++;
return;
}
int tm = (tl + tr) / 2;
if((tm - tl + 1) * K != tree[id * 2] )
get_ans(id * 2, tl, tm);
if( (tr - (tm + 1) + 1) * K != tree[id * 2 + 1] )
get_ans(id * 2 + 1, tm + 1, tr);
}
void solve(){
cin >> K >> n;
build(1, 0, n - 1);
for(int i = 0; i < n; ){
string ch; cin >> ch;
if( ch == "b" ){
int times; cin >> times;
int num; cin >> num;
for(int k = 0; k < times; ++k, ++i){
update(1, 0, n - 1, num);
}
} else {
int num = stoi(ch);
update(1, 0, n - 1, num);
++i;
}
/*for(int i = 1; i <= 7; ++i){
cout << tree[i] << " ";
}
cout << '\n';*/
}
res = 0, used = 0;
get_ans(1, 0, n - 1);
cout << used << " " << res << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int t; cin >> t;
while(t--)
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPiAvLyBDb21tb24gZmlsZQovLyNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAvLyBJbmNsdWRpbmcgdHJlZV9vcmRlcl9zdGF0aXN0aWNzX2ludF91cGRhdGUKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwovL3VzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwovL3R5cGVkZWYgdHJlZTwgcGFpcjxpbnQsIGludD4sIG51bGxfdHlwZSwgbGVzczxwYWlyPGludCwgaW50Pj4sIHJiX3RyZWVfdGFnLCB0cmVlX29yZGVyX3N0YXRpc3RpY3NfaW50X3VwZGF0ZT4KLy9vcmRlcmVkX3NldDsKaW50IGR4W10gPSB7MCwgMSwgMCwgLTF9OwppbnQgZHlbXSA9IHstMSwgMCwgMSwgMH07CiNkZWZpbmUgWCBmaXJzdAojZGVmaW5lIFkgc2Vjb25kCiNkZWZpbmUgaW50IGxvbmcgbG9uZyBpbnQgCmNvbnN0IGludCBNQVhOID0gKGludCkxZTYgKyAxMDsKY29uc3QgaW50IE1PRCA9IDEwMDAwMDAwMDc7CgppbnQgSywgbjsKaW50IHRyZWVbNCAqIE1BWE5dOwoKdm9pZCBidWlsZChpbnQgaWQsIGludCB0bCwgaW50IHRyKXsKICAgIGlmKHRsID4gdHIpewogICAgICAgIHJldHVybjsKICAgIH0KICAgIGlmKCB0bCA9PSB0ciApewogICAgICAgIHRyZWVbaWRdID0gSzsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpbnQgdG0gPSAodGwgKyB0cikgLyAyOwogICAgYnVpbGQoaWQgKiAyLCB0bCwg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Z2V0X2FucyhpZCAqIDIsIHRsLCB0bSk7CiAgICBpZiggICh0ciAtICh0bSArIDEpICsgMSkgKiBLICAhPSB0cmVlW2lkICogMiArIDFdICkKICAgICAgICBnZXRfYW5zKGlkICogMiArIDEsIHRtICsgMSwgdHIpOwp9Cgp2b2lkIHNvbHZlKCl7CiAgICBjaW4gPj4gSyA+PiBuOwogICAgYnVpbGQoMSwgMCwgbiAtIDEpOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47ICl7CiAgICAgICAgc3RyaW5nIGNoOyBjaW4gPj4gY2g7CiAgICAgICAgaWYoIGNoID09ICJiIiApewogICAgICAgICAgICBpbnQgdGltZXM7IGNpbiA+PiB0aW1lczsKICAgICAgICAgICAgaW50IG51bTsgY2luID4+IG51bTsKICAgICAgICAgICAgZm9yKGludCBrID0gMDsgayA8IHRpbWVzOyArK2ssICsraSl7CiAgICAgICAgICAgICAgICB1cGRhdGUoMSwgMCwgbiAtIDEsIG51bSk7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpbnQgbnVtID0gc3RvaShjaCk7CiAgICAgICAgICAgIHVwZGF0ZSgxLCAwLCBuIC0gMSwgbnVtKTsKICAgICAgICAgICAgKytpOwogICAgICAgIH0KICAgICAgICAvKmZvcihpbnQgaSA9IDE7IGkgPD0gNzsgKytpKXsKICAgICAgICAgICAgY291dCA8PCB0cmVlW2ldIDw8ICIgIjsKICAgICAgICB9CiAgICAgICAgY291dCA8PCAnXG4nOyovCiAgICB9CiAgICByZXMgPSAwLCB1c2VkID0gMDsKICAgIGdldF9hbnMoMSwgMCwgbiAtIDEpOwogICAgY291dCA8PCB1c2VkIDw8ICIgIiA8PCByZXMgPDwgJ1xuJzsKICAgIAoKCgogICAgCn0KIAppbnQzMl90IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpO2Npbi50aWUobnVsbHB0cik7Y291dC50aWUobnVsbHB0cik7IAogICAgaW50IHQ7IGNpbiA+PiB0OwogICAgd2hpbGUodC0tKQogICAgICAgIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfSA=