Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry.

There is an l-meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travels continuously back and forth between the banks so long as it is carrying a car or there is at least one car waiting at either bank. Whenever the ferry arrives at one of the banks, it unloads its cargo and loads up cars that are waiting to cross as long as they fit on its deck. The cars are loaded in the order of their arrival; ferry's deck accommodates only one lane of cars. The ferry is initially on the left bank where it broke and it took quite some time to fix it. In the meantime, lines of cars formed on both banks that await to cross the river.

The first line of input contains c, the number of test cases. Each test case begins with l, m. m lines follow describing the cars that arrive in this order to be transported. Each line gives the length of a car (in centimeters), and the bank at which the car arrives ("left" or "right").

For each test case, output one line giving the number of times the ferry has to cross the river in order to serve all waiting cars.

``````4
20 4
380 left
720 left
1340 right
1040 left
15 4
380 left
720 left
1340 right
1040 left
15 4
380 left
720 left
1340 left
1040 left
15 4
380 right
720 right
1340 right
1040 right
``````

``````3
3
5
6
``````

``````#include <iostream>
#define MAX 10001
using namespace std;
int l[MAX];
int r[MAX];
int getTime(int s[],int n,int len)
{
int count=1;
int sum=0;
for(int i=0;i<n;i++)
{
if(sum+s[i]<=len)
{
sum+=s[i];
}
else
{
sum=s[i];
count++;
}
}
return count;
}
int main()
{
int T,n;
int kl,kr;
int summer_len;
char temp;
int i,t;
cin>>T;
while(T--)
{
kl=kr=0;
cin>>summer_len>>n;
summer_len*=100;
for(i=0;i<n;i++)
{
cin>>t>>temp;
if(temp=='l')
{
l[kl++]=t;
}
else
{
r[kr++]=t;
}
}
int t1,t2;
t1=getTime(l,kl,summer_len);
t2=getTime(r,kr,summer_len);
t1=t1*2-1;
t2<<=1;
cout<<(t1>t2?t1:t2)<<endl;
}
return 0;
}
``````

``````#include <stdio.h>

char b;

main(){
scanf("%d",&N);
while (N--) {
k = 0;
scanf("%d%d",&l,&m);
for (i=0;i<m;i++) {
scanf("%d%s",&x[i],&b[i]);
}
lp=rp=k=0;  l *= 100;
for(;;){
if (rp >= m && lp >=m) break;
for(;lp<m;lp++) {
if (b[lp] != 'l') continue;
else break;
}
if (rp >= m && lp >= m) break;
for(;rp<m;rp++) {
if (b[rp] != 'r') continue;