#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define EGRY \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
const int MAX = 1e6 + 100;
/*
yaaaaaaaaaaaaaaaaaaaaaaaaaaaayyyyyyyyy
*/
bool is_left(string &str)
{
return (str == "left");
}
bool is_right(string &str)
{
return (str == "right");
}
void solve()
{
ll l, n;
cin >> l >> n;
l *= 100;
bool left = true;
ll res = 0;
queue<pair<ll, string>> leftCars;
queue<pair<ll, string>> rightCars;
while (n--)
{
ll meter;
string dir;
cin >> meter >> dir;
if (is_left(dir))
{
leftCars.push({meter, dir});
}
else
{
rightCars.push({meter, dir});
}
}
while (!leftCars.empty() || !rightCars.empty())
{
if (left)
{
ll sum = 0;
while (sum <= l && !leftCars.empty())
{
sum += leftCars.front().first;
if (sum > l)
{
break;
}
leftCars.pop();
}
}
else
{
ll sum = 0;
while (sum <= l && !rightCars.empty())
{
sum += rightCars.front().first;
if (sum > l)
{
break;
}
rightCars.pop();
}
}
left = !left;
res++;
}
cout << res << endl;
}
int main()
{
EGRY int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBsbCBsb25nIGxvbmcKCiNkZWZpbmUgRUdSWSAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IFwKICAgIGNpbi50aWUoTlVMTCk7Cgpjb25zdCBpbnQgTUFYID0gMWU2ICsgMTAwOwoKLyoKCiAgICB5YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYXl5eXl5eXl5eQoKKi8KCmJvb2wgaXNfbGVmdChzdHJpbmcgJnN0cikKewogICAgcmV0dXJuIChzdHIgPT0gImxlZnQiKTsKfQoKYm9vbCBpc19yaWdodChzdHJpbmcgJnN0cikKewogICAgcmV0dXJuIChzdHIgPT0gInJpZ2h0Iik7Cn0KCnZvaWQgc29sdmUoKQp7CiAgICBsbCBsLCBuOwogICAgY2luID4+IGwgPj4gbjsKICAgIGwgKj0gMTAwOwoKICAgIGJvb2wgbGVmdCA9IHRydWU7CiAgICBsbCByZXMgPSAwOwoKICAgIHF1ZXVlPHBhaXI8bGwsIHN0cmluZz4+IGxlZnRDYXJzOwogICAgcXVldWU8cGFpcjxsbCwgc3RyaW5nPj4gcmlnaHRDYXJzOwoKICAgIHdoaWxlIChuLS0pCiAgICB7CiAgICAgICAgbGwgbWV0ZXI7CiAgICAgICAgc3RyaW5nIGRpcjsKICAgICAgICBjaW4gPj4gbWV0ZXIgPj4gZGlyOwogICAgICAgIGlmIChpc19sZWZ0KGRpcikpCiAgICAgICAgewogICAgICAgICAgICBsZWZ0Q2Fycy5wdXNoKHttZXRlciwgZGlyfSk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHJpZ2h0Q2Fycy5wdXNoKHttZXRlciwgZGlyfSk7CiAgICAgICAgfQogICAgfQoKICAgIHdoaWxlICghbGVmdENhcnMuZW1wdHkoKSB8fCAhcmlnaHRDYXJzLmVtcHR5KCkpCiAgICB7CiAgICAgICAgaWYgKGxlZnQpCiAgICAgICAgewogICAgICAgICAgICBsbCBzdW0gPSAwOwogICAgICAgICAgICB3aGlsZSAoc3VtIDw9IGwgJiYgIWxlZnRDYXJzLmVtcHR5KCkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN1bSArPSBsZWZ0Q2Fycy5mcm9udCgpLmZpcnN0OwogICAgICAgICAgICAgICAgaWYgKHN1bSA+IGwpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0Q2Fycy5wb3AoKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBsbCBzdW0gPSAwOwogICAgICAgICAgICB3aGlsZSAoc3VtIDw9IGwgJiYgIXJpZ2h0Q2Fycy5lbXB0eSgpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzdW0gKz0gcmlnaHRDYXJzLmZyb250KCkuZmlyc3Q7CiAgICAgICAgICAgICAgICBpZiAoc3VtID4gbCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHJpZ2h0Q2Fycy5wb3AoKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZWZ0ID0gIWxlZnQ7CiAgICAgICAgcmVzKys7CiAgICB9CgogICAgY291dCA8PCByZXMgPDwgZW5kbDsKfQoKaW50IG1haW4oKQp7CiAgICBFR1JZIGludCB0ID0gMTsKICAgIGNpbiA+PiB0OwoKICAgIHdoaWxlICh0LS0pCiAgICB7CiAgICAgICAgc29sdmUoKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==