#include <bits/stdc++.h>
using namespace std;
queue <pair <int, int> > cars[2];
long long tmes[10005];
long long tme,inp_tme,n,t,m,c,po,carsloaded;
string dum;
int main()
{
cin.sync_with_stdio(0);
cin.tie(0);
cin >> c;
while (c--) {
cin >> n >> t >> m;
for (int i=0;i<m;++i) {
cin >> inp_tme >> dum;
if (dum=="left") cars[0].push(make_pair(inp_tme,i));
else cars[1].push(make_pair(inp_tme,i));
}
tme=0;
po=0;
carsloaded=0;
while (!cars[0].empty() || !cars[1].empty()) {
carsloaded=0;
if (!cars[po].empty()) {
if (cars[po].front().first > tme) {
if (!cars[(po+1)&1].empty() && (cars[po].front().first > cars[(po+1)&1].front().first)) {
tme=cars[(po+1)&1].front().first;
po=(po+1)&1;
tme+=t;
continue;
}
else tme=cars[po].front().first;
}
while ((carsloaded < n) && !cars[po].empty() && (cars[po].front().first <= tme)) { ++carsloaded; tmes[cars[po].front().second]=tme+t; cars[po].pop(); }
}
tme+=t;
po=(po+1)&1;
}
for (int i=0;i<m;++i) cout << tmes[i] << '\n';
if (c>0) cout << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnF1ZXVlIDxwYWlyIDxpbnQsIGludD4gPiBjYXJzWzJdOwpsb25nIGxvbmcgdG1lc1sxMDAwNV07CmxvbmcgbG9uZyB0bWUsaW5wX3RtZSxuLHQsbSxjLHBvLGNhcnNsb2FkZWQ7CnN0cmluZyBkdW07CmludCBtYWluKCkKewoJY2luLnN5bmNfd2l0aF9zdGRpbygwKTsKCWNpbi50aWUoMCk7CgljaW4gPj4gYzsKCXdoaWxlIChjLS0pIHsKCQljaW4gPj4gbiA+PiB0ID4+IG07CgkJZm9yIChpbnQgaT0wO2k8bTsrK2kpIHsKCQkJY2luID4+IGlucF90bWUgPj4gZHVtOwoJCQlpZiAoZHVtPT0ibGVmdCIpIGNhcnNbMF0ucHVzaChtYWtlX3BhaXIoaW5wX3RtZSxpK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