Dreamy Putata
시간 제한6초메모리 제한2048 MB
각 칸마다 주어진 확률로 상하좌우로 움직이는 토러스 격자(m은 최대 5)에서, 한 칸의 확률을 바꾸는 갱신과 두 칸 사이의 기대 도달 시간을 묻는 질의를 10^9+7로 나눈 값으로 처리한다.
문제
Putata is dreaming that he got lost in a phantom grid world of size . The rows and columns of the grid are numbered from to and to , respectively. Putata has no idea how to escape from the phantom world, so he decides to walk randomly. Assuming Putata is now at , he will:
- Move to with probability .
- Move to with probability .
- Move to with probability .
- Move to with probability .
You need to perform operations. Each operation is one of the following:
- "
1}' (, , , ): Change the values of , , , and into , , , and , respectively. - "
2" (, , ): Assuming Putata is now at , he is wondering what is the expected number of steps that he will take when he reaches the target position for the first time.
Please write a program to answer his questions.
입력
The first line of the input contains two integers and (, ) denoting the size of the phantom grid world.
In the next lines, the -th line contains integers (, ).
In the next lines, the -th line contains integers (, ).
In the next lines, the -th line contains integers (, ).
In the next lines, the -th line contains integers (, ).
It is guaranteed that holds for all pairs of where and .
The next line contains a single integer () denoting the number of operations.
Each of the next lines describes an operation in the format described in the statement above.
출력
For each test query, print a single line containing an integer: the expected number of steps that Putata will take when he reaches the target position for the first time.
More precisely, assuming the reduced fraction of the answer is , you should output the minimum non-negative integer such that . You may safely assume that such always exists in all test cases.