863_C. 1-2-3
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". 

So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. 

Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. 

Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. 

Input

The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). 

Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). 

Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). 

Output

Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games.

Examples

Input

10 2 1
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2


Output

1 9


Input

8 1 1
2 2 1
3 3 1
3 1 3
1 1 1
2 1 1
1 2 3


Output

5 2


Input

5 1 1
1 2 2
2 2 2
2 2 2
1 2 2
2 2 2
2 2 2


Output

0 0

Note

In the second example game goes like this:

<image>

The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
```python
k, a, b = map(int, input().split())
A = []
for _ in range(3):
	temp = [int(x) for x in input().split()]
	A.append(temp)
B = []
for _ in range(3):
	temp = [int(x) for x in input().split()]
	B.append(temp)
flag, ac, bc, cur = 0, 0, 0, 1
m = {}
ans1, ans2 = [0]*1000, [0]*1000
while cur <= k:
	if (a, b) in m and flag != 1:
		add1 = ans1[cur-1] - ans1[m[(a, b)]-1]
		add2 = ans2[cur-1] - ans2[m[(a, b)]-1]
		l = cur-m[(a, b)]
		times = (k-(cur-1))//l
		ac += add1*times
		bc += add2*times
		cur += l*((k-(cur-1))//l)
		cur -= 1
		# x, y = a-1, b-1
		# a, b = A[x][y], B[x][y]
		flag = 1
	else:
		m[(a, b)] = cur
		if cur <= 500:
			ans1[cur], ans2[cur] = ans1[cur-1], ans2[cur-1]
		if a == b%3 + 1:
			ac += 1
			if cur <= 500:
				ans1[cur] += 1
		if b == a%3 + 1:
			bc += 1
			if cur <= 500:
				ans2[cur] += 1
		x, y = a-1, b-1
		a, b = A[x][y], B[x][y]
	cur += 1
print(ac, bc)

```