File size: 18,995 Bytes
5fed0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
Story
--------
Takahashi, who loves loop lines, is playing with a toy train.
As shown in the figure below, this toy consists of square tiles containing railroad lines.
By rotating the tiles, he can connect lines and play with toy trains running on the lines.
Because Takahashi has two toy trains, please create two large loop lines as much as possible.

<table>
<tr align="center">
<td>
<svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg">
<rect fill="white" height="100" width="100" x="-5" y="-5"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/>
<line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/>
<defs>
<g id="rail1" stroke-width="2">
<line x1="12" x2="12" y1="0" y2="30"/>
<line x1="18" x2="18" y1="0" y2="30"/>
<line x1="12" x2="18" y1="3" y2="3"/>
<line x1="12" x2="18" y1="9" y2="9"/>
<line x1="12" x2="18" y1="15" y2="15"/>
<line x1="12" x2="18" y1="21" y2="21"/>
<line x1="12" x2="18" y1="27" y2="27"/>
</g>
<g fill="none" id="rail2" stroke-width="2">
<path d="M12,0 A12,12 0 0,1 0,12"/>
<path d="M18,0 A18,18 0 0,1 0,18"/>
<line x1="12" x2="18" y1="2" y2="3"/>
<line x1="11" x2="16" y1="5" y2="8"/>
<line x1="8" x2="13" y1="8" y2="13"/>
<line x1="5" x2="8" y1="11" y2="16"/>
<line x1="2" x2="3" y1="12" y2="18"/>
</g>
</defs>
<use href="#rail1" stroke="silver" x="0" y="0"/>
<use href="#rail2" stroke="silver" x="30" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(180,45,15)" x="30" y="0"/>
<use href="#rail2" stroke="silver" x="60" y="0"/>
<use href="#rail2" stroke="silver" x="0" y="30"/>
<use href="#rail2" stroke="silver" transform="rotate(180,15,45)" x="0" y="30"/>
<use href="#rail2" stroke="silver" x="30" y="30"/>
<use href="#rail2" stroke="silver" transform="rotate(180,45,45)" x="30" y="30"/>
<use href="#rail2" stroke="silver" transform="rotate(180,75,45)" x="60" y="30"/>
<use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/>
<use href="#rail2" stroke="silver" transform="rotate(90,15,75)" x="0" y="60"/>
<use href="#rail2" stroke="silver" x="30" y="60"/>
<use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/>
<use href="#rail2" stroke="silver" x="60" y="60"/>
</svg>
</td>
<td>
<svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg">
<rect fill="white" height="100" width="100" x="-5" y="-5"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/>
<line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/>
<defs>
<g id="rail1" stroke-width="2">
<line x1="12" x2="12" y1="0" y2="30"/>
<line x1="18" x2="18" y1="0" y2="30"/>
<line x1="12" x2="18" y1="3" y2="3"/>
<line x1="12" x2="18" y1="9" y2="9"/>
<line x1="12" x2="18" y1="15" y2="15"/>
<line x1="12" x2="18" y1="21" y2="21"/>
<line x1="12" x2="18" y1="27" y2="27"/>
</g>
<g fill="none" id="rail2" stroke-width="2">
<path d="M12,0 A12,12 0 0,1 0,12"/>
<path d="M18,0 A18,18 0 0,1 0,18"/>
<line x1="12" x2="18" y1="2" y2="3"/>
<line x1="11" x2="16" y1="5" y2="8"/>
<line x1="8" x2="13" y1="8" y2="13"/>
<line x1="5" x2="8" y1="11" y2="16"/>
<line x1="2" x2="3" y1="12" y2="18"/>
</g>
</defs>
<use href="#rail1" stroke="silver" x="0" y="0"/>
<use href="#rail2" stroke="silver" x="30" y="0"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,45,15)" x="30" y="0"/>
</g>
<g>
<use href="#rail2" stroke="brown" transform="rotate(270,75,15)" x="60" y="0"/>
</g>
<use href="#rail2" stroke="silver" x="0" y="30"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,15,45)" x="0" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="30" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,45,45)" x="30" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="60" y="30"/>
</g>
<use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(90,15,75)" x="0" y="60"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="30" y="60"/>
</g>
<use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/>
<use href="#rail2" stroke="silver" x="60" y="60"/>
</svg>
</td>
</tr>
<tr align="center">
<td>
Initial State.
</td>
<td>
After rotating the top-right tile and the middle-right tile.
</td>
</tr>
</table>

Problem Statement
--------
You are given tiles containing railroad lines arranged in a 30 x 30 square.
There are 8 types of tiles by distinguishing rotations which are numbered as follows.


<svg height="70" id="vis" viewBox="-5 -5 250 70" width="250" xmlns="http://www.w3.org/2000/svg">
<rect fill="white" height="70" width="250" x="-5" y="-5"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="0" y2="0"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="30" y2="30"/>
<line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="60" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="120" x2="120" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="150" x2="150" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="180" x2="180" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="210" x2="210" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="240" x2="240" y1="0" y2="60"/>
<text font-size="22" text-anchor="middle" x="15" y="55">
0
</text>
<text font-size="22" text-anchor="middle" x="45" y="55">
1
</text>
<text font-size="22" text-anchor="middle" x="75" y="55">
2
</text>
<text font-size="22" text-anchor="middle" x="105" y="55">
3
</text>
<text font-size="22" text-anchor="middle" x="135" y="55">
4
</text>
<text font-size="22" text-anchor="middle" x="165" y="55">
5
</text>
<text font-size="22" text-anchor="middle" x="195" y="55">
6
</text>
<text font-size="22" text-anchor="middle" x="225" y="55">
7
</text>
<defs>
<g id="rail1" stroke-width="2">
<line x1="12" x2="12" y1="0" y2="30"/>
<line x1="18" x2="18" y1="0" y2="30"/>
<line x1="12" x2="18" y1="3" y2="3"/>
<line x1="12" x2="18" y1="9" y2="9"/>
<line x1="12" x2="18" y1="15" y2="15"/>
<line x1="12" x2="18" y1="21" y2="21"/>
<line x1="12" x2="18" y1="27" y2="27"/>
</g>
<g fill="none" id="rail2" stroke-width="2">
<path d="M12,0 A12,12 0 0,1 0,12"/>
<path d="M18,0 A18,18 0 0,1 0,18"/>
<line x1="12" x2="18" y1="2" y2="3"/>
<line x1="11" x2="16" y1="5" y2="8"/>
<line x1="8" x2="13" y1="8" y2="13"/>
<line x1="5" x2="8" y1="11" y2="16"/>
<line x1="2" x2="3" y1="12" y2="18"/>
</g>
</defs>
<use href="#rail2" stroke="silver" x="0" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(270,45,15)" x="30" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(180,75,15)" x="60" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(90,105,15)" x="90" y="0"/>
<use href="#rail2" stroke="silver" x="120" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(180,135,15)" x="120" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(270,165,15)" x="150" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(90,165,15)" x="150" y="0"/>
<use href="#rail1" stroke="silver" transform="rotate(90,195,15)" x="180" y="0"/>
<use href="#rail1" stroke="silver" x="210" y="0"/>
</svg>

Tiles 0 to 3 contain one curved line, tiles 4 and 5 contain two curved lines, and tiles 6 and 7 contain one straight line.
Each tile can be rotated every 90 degrees.
By rotating a tile 90 degrees counterclockwise, the tile will become as follows.

<svg height="70" id="vis" viewBox="-5 -5 250 70" width="250" xmlns="http://www.w3.org/2000/svg">
<rect fill="white" height="70" width="250" x="-5" y="-5"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="0" y2="0"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="30" y2="30"/>
<line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="60" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="120" x2="120" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="150" x2="150" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="180" x2="180" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="210" x2="210" y1="0" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="240" x2="240" y1="0" y2="60"/>
<text font-size="22" text-anchor="middle" x="15" y="55">
1
</text>
<text font-size="22" text-anchor="middle" x="45" y="55">
2
</text>
<text font-size="22" text-anchor="middle" x="75" y="55">
3
</text>
<text font-size="22" text-anchor="middle" x="105" y="55">
0
</text>
<text font-size="22" text-anchor="middle" x="135" y="55">
5
</text>
<text font-size="22" text-anchor="middle" x="165" y="55">
4
</text>
<text font-size="22" text-anchor="middle" x="195" y="55">
7
</text>
<text font-size="22" text-anchor="middle" x="225" y="55">
6
</text>
<defs>
<g id="rail1" stroke-width="2">
<line x1="12" x2="12" y1="0" y2="30"/>
<line x1="18" x2="18" y1="0" y2="30"/>
<line x1="12" x2="18" y1="3" y2="3"/>
<line x1="12" x2="18" y1="9" y2="9"/>
<line x1="12" x2="18" y1="15" y2="15"/>
<line x1="12" x2="18" y1="21" y2="21"/>
<line x1="12" x2="18" y1="27" y2="27"/>
</g>
<g fill="none" id="rail2" stroke-width="2">
<path d="M12,0 A12,12 0 0,1 0,12"/>
<path d="M18,0 A18,18 0 0,1 0,18"/>
<line x1="12" x2="18" y1="2" y2="3"/>
<line x1="11" x2="16" y1="5" y2="8"/>
<line x1="8" x2="13" y1="8" y2="13"/>
<line x1="5" x2="8" y1="11" y2="16"/>
<line x1="2" x2="3" y1="12" y2="18"/>
</g>
</defs>
<use href="#rail2" stroke="silver" transform="rotate(270,15,15)" x="0" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(180,45,15)" x="30" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(90,75,15)" x="60" y="0"/>
<use href="#rail2" stroke="silver" x="90" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(270,135,15)" x="120" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(90,135,15)" x="120" y="0"/>
<use href="#rail2" stroke="silver" x="150" y="0"/>
<use href="#rail2" stroke="silver" transform="rotate(180,165,15)" x="150" y="0"/>
<use href="#rail1" stroke="silver" x="180" y="0"/>
<use href="#rail1" stroke="silver" transform="rotate(90,225,15)" x="210" y="0"/>
</svg>

Since there are no branches on the lines, each line is part of a path or cycle.
A set of lines forming a cycle is called a "loop line," and its length is defined as the number of times to move from a tile to its adjacent tile in a round trip along the loop line.
For example, the loop line below consists of 7 tiles, but its length is 8 because it passes through the center tile twice.

<svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg">
<rect fill="white" height="100" width="100" x="-5" y="-5"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/>
<line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/>
<line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/>
<line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/>
<defs>
<g id="rail1" stroke-width="2">
<line x1="12" x2="12" y1="0" y2="30"/>
<line x1="18" x2="18" y1="0" y2="30"/>
<line x1="12" x2="18" y1="3" y2="3"/>
<line x1="12" x2="18" y1="9" y2="9"/>
<line x1="12" x2="18" y1="15" y2="15"/>
<line x1="12" x2="18" y1="21" y2="21"/>
<line x1="12" x2="18" y1="27" y2="27"/>
</g>
<g fill="none" id="rail2" stroke-width="2">
<path d="M12,0 A12,12 0 0,1 0,12"/>
<path d="M18,0 A18,18 0 0,1 0,18"/>
<line x1="12" x2="18" y1="2" y2="3"/>
<line x1="11" x2="16" y1="5" y2="8"/>
<line x1="8" x2="13" y1="8" y2="13"/>
<line x1="5" x2="8" y1="11" y2="16"/>
<line x1="2" x2="3" y1="12" y2="18"/>
</g>
</defs>
<use href="#rail1" stroke="silver" x="0" y="0"/>
<use href="#rail2" stroke="silver" x="30" y="0"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,45,15)" x="30" y="0"/>
</g>
<g>
<use href="#rail2" stroke="brown" transform="rotate(270,75,15)" x="60" y="0"/>
</g>
<use href="#rail2" stroke="silver" x="0" y="30"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,15,45)" x="0" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="30" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" transform="rotate(180,45,45)" x="30" y="30"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="60" y="30"/>
</g>
<use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/>
<g>
<use href="#rail2" stroke="brown" transform="rotate(90,15,75)" x="0" y="60"/>
</g>
<g>
<use href="#rail2" stroke="brown" x="30" y="60"/>
</g>
<use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/>
<use href="#rail2" stroke="silver" x="60" y="60"/>
</svg>

Your task is to determine the number of times to rotate each tile.

Scoring
--------
Let $L_1$ be the length of the longest loop line obtained by rotating the tiles according to the output, and $L_2$ be the length of the second longest one ($L_1=L_2$ if there is more than one longest one).
Then, you will get a score of $L_1\times L_2$.
If the number of loop lines is less than or equal to $1$, the score for that test case is $0$.

There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Hints on how to compute the length of a loop line.
<details>
<font color="red">
Pseudo code has been updated.
</font>
You can compute the length of a loop line, for example, as follows.
Let `tiles` be a two-dimensional array containing the tile states.
By numbering the directions 0, 1, 2, 3 in order of left, up, right, and down, the change in coordinates is represented by the arrays `di = [0, -1, 0, 1]` and `dj = [-1, 0, 1, 0]`.
When a train enters a tile of state `t` from its adjacent tile in direction `d`, let `to[t][d]` be the direction to the next tile, or `-1` if the train cannot enter from such a direction, then we obtain the following two-dimensional array.
```
to = [
	[1, 0, -1, -1],
	[3, -1, -1, 0],
	[-1, -1, 3, 2],
	[-1, 2, 1, -1],
	[1, 0, 3, 2],
	[3, 2, 1, 0],
	[2, -1, 0, -1],
	[-1, 3, -1, 1],
];
```
When a train enters tile at position `(i, j)` from its adjacent tile in direction `d`, you can update these variables as follows.

```
d2 = to[tiles[i][j]][d]; // Direction to the next tile
if (d2 == -1) return 0; // The line is broken.
i += di[d2];
j += dj[d2];
if (i < 0 || i >= 30 || j < 0 || j >= 30) return 0; // The line is broken.
d = (d2 + 2) % 4; // Direction to the previous tile.
```
After repeating this process until the train returns to its initial position and direction (note that it may pass through the same tile twice), the number of iterations is the length of the loop line.
```
// Suppose that a train enters a tile (si, sj) from direction sd.
i = si;
j = sj;
d = sd;
length = 0;
loop {
	d2 = to[tiles[i][j]][d];
	if (d2 == -1) return 0;
	i += di[d2];
	j += dj[d2];
	if (i < 0 || i >= 30 || j < 0 || j >= 30) return 0;
	d = (d2 + 2) % 4;
	length += 1;
	if (i == si && j == sj && d == sd) return length;
}
```
</details>

Input
--------
Input is given from Standard Input in the following format:

~~~
$t_{0,0}$ $\cdots$ $t_{0,29}$
$\vdots$
$t_{29,0}$ $\cdots$ $t_{29,29}$
~~~

Each $t_{i,0}\cdots t_{i,29}$ is a string of $30$ characters.
Let $(i,j)$ denote the $i$-th $(0\leq i\leq 29)$ tile from the top and $j$-th $(0\leq j\leq 29)$ tile from the left.
Then, $t_{i,j}$ is an integer between $0$ and $7$ representing the state of the tile $(i, j)$.

Output
--------
Let $r_{i,j}$ ($0\leq r_{i,j}\leq 3$) be the number of times the tile $(i,j)$ is rotated 90 degrees counterclockwise.
Output a string of length $900$ such that the $30i+j$-th character is $r_{i,j}$ in one line to Standard Output.

<a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.html?lang=en&show=example">Show example</a>


Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.

Each $t_{i,j}$ is independently generated as follows.

- With probability 25%, $t_{i,j}=\mathrm{rand}(0, 3)$.
- With probability 50%, $t_{i,j}=\mathrm{rand}(4, 5)$.
- With probability 25%, $t_{i,j}=\mathrm{rand}(6, 7)$.


Tools (Input generator and visualizer)
--------
- <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
- <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
	- <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.


<font color="red">**Sharing visualization results is not allowed until the end of the contest. **</font>

{sample example}