You all must be familiar with the chess-board having 8∗8 squares of alternate black and white cells. Well, here we have for you a similar N∗M size board with similar arrangement of black and white cells.
A few of these cells have Horses placed over them. Each horse is unique. Now these horses are not the usual horses which could jump to any of the 8 positions they usually jump in. They can move only if there is another horse on one of the 8-positions that it can go to usually and then both the horses will swap their positions. This swapping can happen infinitely times.
A photographer was assigned to take a picture of all the different ways that the horses occupy the board! Given the state of the board, calculate answer. Since this answer may be quite large, calculate in modulo 1097.
First line contains T which is the number of test cases.
T test cases follow first line of each containing three integers N, M and Q where N,M is the size of the board and Q is the number of horses on it.
Q lines follow each containing the 2 integers X and Y which are the coordinates of the Horses.
For each test case, output the number of photographs taken by photographer.
Case 1: In this case we have Horse 1 and Horse 4 can interchange. Same for Horse 2 and Horse 3. Thus we have 4 ways.
Case 2: In this case we have Horse 2 and Horse 3 can interchange. Rest cannot.