#14891 톱니바퀴
import sys
from collections import deque
input = sys.stdin.readline
wheel = []
for _ in range(4):
wheel.append(deque(input().rstrip()))
rotate_num = int(input())
rotate_list = []
for _ in range(rotate_num):
rotate_list.append(list(map(int, input().split())))
def rotate(standard, num, direction):
if abs(standard - num) % 2 == 1:
direction = -1*direction
if direction == 1:
temp = wheel[num].pop()
wheel[num].insert(0, temp)
else:
temp = wheel[num].popleft()
wheel[num].append(temp)
for num, direction in rotate_list:
num -= 1
left = num-1
right = num+1
while(True):
if 0 <= left and wheel[left+1][6] != wheel[left][2]:
left -= 1
else:
break
while(True):
if right < 4 and wheel[right-1][2] != wheel[right][6]:
right += 1
else:
break
for i in range(left+1, right):
rotate(num, i, direction)
answer = 0
for i in range(4):
if wheel[i][0] == '1':
answer += pow(2, i)
print(answer)
최근댓글