1
#include <cstdio>
2
#include <memory.h>
3
4
const int MAXN = 900 ;
5
const int SIZE = 27 ;
6
7
int P , Q , arr[MAXN][2] , sum ;
8
bool ok , visited[SIZE][SIZE] ;
9
10
void DFS(const int& x, const int& y, int num )
11

{
12
if ( ok ) return ;
13
14
arr[num][0] = x , arr[num][1] = y ;
15
if ( num == sum )
16
{
17
ok = true ;
18
return ;
19
}
20
21
if ( y - 2 > 0 )
22
{
23
if ( x - 1 > 0 && !visited[x - 1][y - 2] )
24
{
25
visited[x - 1][y - 2] = true ;
26
DFS( x - 1, y - 2, num + 1 ) ;
27
visited[x - 1][y - 2] = false ;
28
}
29
if ( x + 1 <= P && !visited[x + 1][y - 2] )
30
{
31
visited[x + 1][y - 2] = true ;
32
DFS( x + 1, y - 2, num + 1 ) ;
33
visited[x + 1][y - 2] = false ;
34
}
35
}
36
if ( x - 2 > 0 )
37
{
38
if ( y - 1 > 0 && !visited[x - 2][y - 1] )
39
{
40
visited[x - 2][y - 1] = true ;
41
DFS( x - 2, y - 1, num + 1 ) ;
42
visited[x - 2][y - 1] = false ;
43
}
44
}
45
if ( x + 2 <= P )
46
{
47
if ( y - 1 > 0 && !visited[x + 2][y - 1] )
48
{
49
visited[x + 2][y - 1] = true ;
50
DFS( x + 2, y - 1, num + 1 ) ;
51
visited[x + 2][y - 1] = false ;
52
}
53
}
54
if ( x - 2 > 0 )
55
{
56
if ( y + 1 <= Q && !visited[x - 2][y + 1] )
57
{
58
visited[x - 2][y + 1] = true ;
59
DFS( x - 2, y + 1, num + 1 ) ;
60
visited[x - 2][y + 1] = false ;
61
}
62
}
63
if ( x + 2 <= P )
64
{
65
if ( y + 1 <= Q && !visited[x + 2][y + 1] )
66
{
67
visited[x + 2][y + 1] = true ;
68
DFS( x + 2, y + 1, num + 1 ) ;
69
visited[x + 2][y + 1] = false ;
70
}
71
}
72
if ( y + 2 <= Q )
73
{
74
if ( x - 1 > 0 && !visited[x - 1][y + 2] )
75
{
76
visited[x - 1][y + 2] = true ;
77
DFS( x - 1, y + 2, num + 1 ) ;
78
visited[x - 1][y + 2] = false ;
79
}
80
if ( x + 1 <= P && !visited[x + 1][y + 2] )
81
{
82
visited[x + 1][y + 2] = true ;
83
DFS( x + 1, y + 2, num + 1 ) ;
84
visited[x + 1][y + 2] = false ;
85
}
86
}
87
}
88
89
void Init()
90

{
91
ok = false ;
92
memset(visited, 0, sizeof(visited)) ;
93
}
94
int main()
95

{
96
// freopen("in.txt", "r", stdin) ;
97
98
int t , cs ;
99
100
cs = 1 ;
101
scanf("%d", &t) ;
102
103
while ( t-- )
104
{
105
Init() ;
106
107
scanf("%d %d", &P, &Q) ;
108
109
sum = P * Q ;
110
111
visited[1][1] = true ;
112
113
DFS( 1, 1, 1 ) ;
114
115
printf("Scenario #%d:\n", cs) ;
116
cs++ ;
117
118
if ( ok )
119
{
120
for ( int i = 1 ; i <= sum ; ++i )
121
{
122
printf("%c%c", arr[i][1] + 'A' - 1 , arr[i][0] + '0' ) ;
123
}
124
}
125
else
{
126
printf("impossible") ;
127
}
128
printf("\n\n") ;
129
}
130
131
return 0 ;
132
}

2

3

4

5

6

7

8

9

10

11



12

13

14

15

16



17

18

19

20

21

22



23

24



25

26

27

28

29

30



31

32

33

34

35

36

37



38

39



40

41

42

43

44

45

46



47

48



49

50

51

52

53

54

55



56

57



58

59

60

61

62

63

64



65

66



67

68

69

70

71

72

73



74

75



76

77

78

79

80

81



82

83

84

85

86

87

88

89

90



91

92

93

94

95



96

97

98

99

100

101

102

103

104



105

106

107

108

109

110

111

112

113

114

115

116

117

118

119



120

121



122

123

124

125



126

127

128

129

130

131

132
