uva1101測資A

Input:
1 2 2 3 10 20
1 3 2 3 22 33
3 2 2 3 4 5
5 3 2 3 2 3
1 1 2 3 4 5
2 2 1 1 999999999 1000000000
1 1 1 2 999999999 1000000000
2 2 1 2 256 512
21474836 2 1 1 400000000 1000000000
1 2 1 2 7 11
27272727 7272727 2 7 222222222 777777777
24836 28326 3 5 1000103 1000462
30 9 11 15 995550811 996172793
85873 22565 7 7 1000827 1000832
8 6 88 89 984330765 994081136
20 3 111921 191299 314891 13598046
960 948 1 1 999333199 999490030
361 825 5 5 1014 3526
43 1 78 88 986006716 998378755
83540 62119 3 4 1000370 1000638
78244 15668 1 2 1000992 1000996
15 15 2314 2325 993580169 995649314
84 9 14 90 230576086 844373748
25 2 37 60 591784087 615092436
7 1 66 87 3011 9566
13 1 109739 147858 52 28850341
852 475 4 4 991308573 998291450
4 8 22 49 5805 8168
5 4 1035 1632 999122185 999273220
57 8 50 93 808111245 874912805
77 2 197031 198436 209804 11362818
546 367 5 5 993137622 994755181
64 9 90 99 975206439 984334476
58 2 146613 147934 89541 14484328
981 204 5 5 991383562 993438327
817 197 3 4 931887514 971682277
17 4 51 92 909424447 988633431
91 2 2 25 995553116 998737743
691 397 5 5 999815614 999844593
34 2 63 69 999668164 999669086
94076 97742 3 3 1000651 1000913
31 2 12 36 994390976 996334175
719 182 2 2 999243376 999518261
34 7 71 88 7773 8767
185 412 1 2 606974869 851125469
5 5 1808 1835 996641610 998055099
254 734 1 2 990229648 997577974
4 5 81 85 9535 9838
1 1 1692 1976 996331627 997285860
385 369 3 4 991850835 995130383
5 3 1157 1948 997221663 997313802
56 5 183263 197119 125708 22242347
1 3 127951 128122 72212 1120465
908 417 1 3 576257358 122936977
865 841 4 5 995888068 999521894
62346 91448 5 5 1000487 1000704
1 2 154823 165991 430498 44307897
7 9 62 66 155069429 334468841
10 4 156389 197119 234505 46065650
7 9 62 66 155069429 334468841
66654 53423 6 20 1000415 1000976
1 2 80 92 93585546 999750893
852 609 1 2 994678545 999148687
6 5 122663 165436 63952 2523914
4 5 1577 1589 999862117 999899128
588 510 3 4 998461823 999474631
65 7 78 80 995480657 998343333
6 99 2 6 157780021 534052090
68 1 146700 160711 201414 1373526
846 366 4 5 991747044 997550377
2 10 17 19 1942 7774
99 8 78 96 392446505 434929139
237 114 3 3 998922138 999268982
60 4 128705 165049 442656 19754304
29978 26172 4 4 1000199 1000740
15 18 2315 2334 995187262 999469459
31 2 146385 177027 286681 1615555
5 2 49 88 3718 6225
324 150 2 5 999446465 999771068
55269 44041 2 4 1000696 1000922
57 1 152926 198146 103354 39862439
158 349 4 5 982551491 988273439
84 3 195150 196392 40655 25349217
23 6 1 41 131458372 482019958
91 10 98 100 996274540 996766273
1 3 103913 177026 10419 10012159
19 1 18 92 991851411 995480772
84 1 105000 165948 160999 34666375
356 780 4 5 315208531 646980801
10 5 10 20 2658 3598
78135 48290 7 13 1000547 1000712
95 6 95 100 265585058 943355607
20 5 155457 172979 463211 39221787
11 11 2327 2330 994904907 997505503
633 507 3 5 998421039 999479583
43 5 170304 185868 42259 26547394
24656 94334 6 6 1000089 1000710
0 0 0 0 0 0
Output:
Case 1: 1A 2M
Case 2: 1M 2A 1M
Case 3: impossible
Case 4: empty
Case 5: 2A
Case 6: 3A 3M 1A 1M 1A 1M 1A 3M 1A 1M 1A 2M 1A 2M 1A 1M 1A 3M 1A 2M 1A 8M
Case 7: 999999998A
Case 8: 2A 6M
Case 9: 3A 3M
Case 10: 3A 1M
Case 11: 9A
Case 12: impossible
Case 13: 561A 1M 6A 4M
Case 14: impossible
Case 15: 62A 1M 2A 7M
Case 16: 1M
Case 17: 2M 162A 1M
Case 18: 3A
Case 19: 22930387A
Case 20: impossible
Case 21: impossible
Case 22: 1155A 4M
Case 23: 1A 7M
Case 24: 44A 19M
Case 25: 421A
Case 26: empty
Case 27: 5A 1M 73A 1M
Case 28: 18A 2M
Case 29: 3122050A 3M
Case 30: 54A 6M
Case 31: 1M
Case 32: 1M 10A 1M 53A 1M
Case 33: 27A 1M 3A 5M
Case 34: empty
Case 35: 1M 23A 1M 50A 1M
Case 36: 30A 2M
Case 37: 49A 10M
Case 38: 83A 2M 1A 1M 1A 1M 1A 2M 1A 11M
Case 39: 1M 6A 1M 122A 1M 68A
Case 40: 229701A 2M 1A 2M 1A 3M
Case 41: impossible
Case 42: 489A 2M 1A 14M
Case 43: 1M 41A 1M 82A 1M
Case 44: 2A 1M 4A 1M 1A
Case 45: 1M 18A 2M
Case 46: 12396A 6M
Case 47: 7A 1M 171A 1M
Case 48: 76A 2M
Case 49: 996329935A
Case 50: 18A 1M 337A 1M
Case 51: 2462045A 4M
Case 52: empty
Case 53: empty
Case 54: impossible
Case 55: 1A 1M 525A 1M
Case 56: impossible
Case 57: 2M
Case 58: 7M
Case 59: 1M
Case 60: 7M
Case 61: impossible
Case 62: 21M
Case 63: 3A 1M 90A 1M
Case 64: empty
Case 65: 399551A 4M
Case 66: 6A 1M 267A 1M
Case 67: 17A 1M 2A 1M 6A 5M
Case 68: 27A 3M
Case 69: 805A
Case 70: 8A 1M 274A 1M
Case 71: 2A 2M
Case 72: 1A 1M 1A 6M
Case 73: 1M 1A 1M 45A 1M 93A 1M
Case 74: 1M
Case 75: impossible
Case 76: 478A 4M
Case 77: 1M
Case 78: 1A 1M 1A 1M 1A 2M 1A 1M 1A 1M
Case 79: 137A 1M 14A 1M
Case 80: impossible
Case 81: empty
Case 82: 51A 1M 11A 1M
Case 83: empty
Case 84: 4A 8M
Case 85: 108A 1M 4A 1M 1A 3M
Case 86: empty
Case 87: 52202705A
Case 88: 667A
Case 89: 2A 2M
Case 90: 10A 2M
Case 91: impossible
Case 92: 1A 8M
Case 93: 1M
Case 94: 351A 5M
Case 95: 6A 1M 67A 1M
Case 96: empty
Case 97: impossible