Ayush travels a lot in Ola cabs.He is so fond of OLA that he dreamt of a game that revolves around the letters 'O,L,A'. In this game, he will ask assign a number i to
all the children and ask them to sit in a matrix in sequential row major order. In this way, the chlidren will adjust themselves in m rows and n columns. Now the real
game begins.When Ayush says a letter, the children should do a task. Along with the letter, Ayush will also say two numbers x and y.
Ayush : O , x , y means all the children in xth row have to be swapped by the children in yth row.
Ayush : L , x , y means all the children in xth column have to be swapped by the children in yth column.
Ayush : A , x , y means print the number assigned to the child in xth row and yth column (Print arr[x-1][y-1])
Help the children to do these tasks in as less time as possible, as Ayush is busy travelling in Ola from Gwalior to MANIT.
Note : 0<=x<=m-1 and 0<=y<=n-1
A sequential row major order implies if there are 12 children with 3 rows and 4 cols, they will be arranged as following:
1 2 3 4
5 6 7 8
9 10 11 12
Input :
Two numbers m and n. (1<=m<=1000, 1<=n<=1000)
Total No of times,t, Ayush is going to say any of O,L or A. (1<=t<=10^8)
Next corresponding t lines will contain three numbers in this format : either O,L or A , x , y
Output:
Each time Ayush says, A, the coresponding element has to be printed.
Sample Input:
3 4
2
O 1 3
A 1 2
Sample Output : 10
Sample Explanation:
Initial matrix : 1 2 3 4
5 6 7 8
9 10 11 12
After O 1 3 : 9 10 11 12
5 6 7 8
1 2 3 4
After A 1 2 : 10 is printed