1 #include <cstdio>
2 #include <cmath>
3 #include <algorithm>
4 #include <iostream>
5 #include <cstring>
6 #include <queue>
7 #include <vector>
8 #define maxn 10005
9 #define L -1
10 #define R 1
11 #define fell 10
12 #define Turning -10
13 #define On 0;
14
15 using namespace std;
16 struct ants{
17 int location;
18 int direction;
19 int inputorder;
20 int state;
21 bool operator < (const ants& a) const{
22 return location <a.location;
23 }
24 }Ant[maxn];
25
26 int main(){
27 //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);}
28
29 int n,l,T;
30 int N;
31 cin>>N;
32 for(int test=1;test<=N;test++){
33 cin>>l>>T>>n;
34 int a;
35 char ch;
36 for(int i=1;i<=n;i++){
37 cin>>a>>ch;
38
39 if(ch == 'R') Ant[i].direction = R;
40 else Ant[i].direction = L;
41 Ant[i].location = a;
42 Ant[i].inputorder = i;
43 }
44 sort(Ant+1,Ant+n+1);
45 int order[maxn];
46 for(int i=1;i<=n;i++){
47 order[Ant[i].inputorder] = i;
48 }
49
50 for(int i=1;i<=n;i++) Ant[i].location += T * Ant[i].direction;
51
52 sort(Ant+1,Ant+n+1);
53
54 for(int i=1;i<=n;i++)
55 if(Ant[i].location < 0 || Ant[i].location > l)
56 Ant[i].state = fell;
57 else if(Ant[i].location == Ant[i+1].location && i < n) {
58 Ant[i].state = Ant [i+1].state = Turning;
59 i++;
60 }
61 else
62 Ant[i].state = On;
63 printf("Case #%d:\n",test);
64
65 for(int i=1;i<=n;i++){
66 int j = order[i];
67 if(Ant[j].state == fell) printf("Fell off\n");
68 else if(Ant[j].state == Turning){
69 printf("%d Turning\n",Ant[j].location);
70 }
71 else
72 printf("%d %c\n",Ant[j].location,Ant[j].direction == R ? 'R' : 'L');
73
74 }
75 printf("\n");
76 }
77 }