Pro.ID21637 TitleFengshui Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21637 AC0 Submit1 Ratio0.00% 时间&空间限制描述Fengshui is an ancient subject in Chinese tradition. Someone considers it as science and someone criticizes it as blind faith. Who knows! However, in modem days, everyone should respect culture from our ancestor! Fengshui focus on geography, environment and staffs' position, all the theory come from a very old book named "YI". YI means change. Everything is always changing in the world. Fengshui wishes to guide changing, make life change to a better situation. Now, let's look at Fengshui's changing. At first we must know about the traditional five elements system which composed by GOLD, WOOD, GROUND, WATER and FIRE. Everything in the world can be represented by one and only one element. For example, river is represented by WATER, HILL is represented by GROUND. Here, we only consider the elements. In this system, one element can kill another element, and one element can born another element. Five elements compose as a circuit, as in Figure 1. Figure 1 Kill and born Every place has eight direction -- east, west, north, south, northeast, northwest, southeast and southwest. Every direction has a represented element. Now, our problem is about the elements at these eight directions which form a Fengshui situation. Figure 2 is an example of one Fengshui situation. But Fengshui situation can change! There're two change ways: (1) TURN: The whole situation turn clockwise one step. Figure 3 shows the situation that situation in Figure 2 makes one TURN change. (2) REBORN: Based on kill and born relation, one direction's element can be killed by another direction's (at any other place) element in the situation, and then the killed element will born out as the new element at its direction. Of course, kill and born are all according as the relation of the system as in Figure 1. In situation of Figure 3, WATER in east can kill FIRE in southeast, then southeast place change to be GROUND, as in Figure 4. Figure 2 Figure 3 Figure 4 Each change, no matter TURN or REBORN, costs one step. Now, there're two Fengshui situations, we want to know is it possible that first one can change to the second one? And if possible, how many steps it needs at least? 输入There're several cases, the first line of input is the number of cases. Every case includes 6 lines, the first 3 lines indicate the first Fengshui situation, the last 3 lines incicate the second Fengshui situation. The format of one situation is as follow, there may be arbitrary blanks between adjacent directions. northwest north northeast 输出Description Fengshui is an ancient subject in Chinese tradition. Someone considers it as science and someone criticizes it as blind faith. Who knows! However, in modem days, everyone should respect culture from our ancestor! Fengshui focus on geography, environment and staffs' position, all the theory come from a very old book named "YI". YI means change. Everything is always changing in the world. Fengshui wishes to guide changing, make life change to a better situation. Now, let's look at Fengshui's changing. At first we must know about the traditional five elements system which composed by GOLD, WOOD, GROUND, WATER and FIRE. Everything in the world can be represented by one and only one element. For example, river is represented by WATER, HILL is represented by GROUND. Here, we only consider the elements. In this system, one element can kill another element, and one element can born another element. Five elements compose as a circuit, as in Figure 1. Figure 1 Kill and born Every place has eight direction -- east, west, north, south, northeast, northwest, southeast and southwest. Every direction has a represented element. Now, our problem is about the elements at these eight directions which form a Fengshui situation. Figure 2 is an example of one Fengshui situation. But Fengshui situation can change! There're two change ways: (1) TURN: The whole situation turn clockwise one step. Figure 3 shows the situation that situation in Figure 2 makes one TURN change. (2) REBORN: Based on kill and born relation, one direction's element can be killed by another direction's (at any other place) element in the situation, and then the killed element will born out as the new element at its direction. Of course, kill and born are all according as the relation of the system as in Figure 1. In situation of Figure 3, WATER in east can kill FIRE in southeast, then southeast place change to be GROUND, as in Figure 4. Figure 2 Figure 3 Figure 4 Each change, no matter TURN or REBORN, costs one step. Now, there're two Fengshui situations, we want to know is it possible that first one can change to the second one? And if possible, how many steps it needs at least? Input There're several cases, the first line of input is the number of cases. Every case includes 6 lines, the first 3 lines indicate the first Fengshui situation, the last 3 lines incicate the second Fengshui situation. The format of one situation is as follow, there may be arbitrary blanks between adjacent directions. northwest north northeast Output For every case, output the number of the least changing steps on a single line. Output -1 on a single line in case of no solution. Sample Input 2 Sample Output 2 Source 样例输入2 样例输出2 作者 |