Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.

That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.

Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.

Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.


-----Input-----

The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.

Next q lines contain turns descriptions, one per line. Each description starts with an integer t_{i} (1 ≤ t_{i} ≤ 3) that defines the type of the operation. For the operation of first and second type integer r_{i} (1 ≤ r_{i} ≤ n) or c_{i} (1 ≤ c_{i} ≤ m) follows, while for the operations of the third type three integers r_{i}, c_{i} and x_{i} (1 ≤ r_{i} ≤ n, 1 ≤ c_{i} ≤ m,  - 10^9 ≤ x_{i} ≤ 10^9) are given.

Operation of the first type (t_{i} = 1) means that signal comes to the input corresponding to row r_{i}, that is it will shift cyclically. Operation of the second type (t_{i} = 2) means that column c_{i} will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row r_{i} and column c_{i} stores value x_{i}.


-----Output-----

Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 10^9 by their absolute value.

If there are multiple valid solutions, output any of them.


-----Examples-----
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8

Output
8 2 
1 8 

Input
3 3 2
1 2
3 2 2 5

Output
0 0 0 
0 0 5 
0 0 0

Difficulty: interview

Starter code:

Solutions:
nmq = input().split(' ')
n, m, q = int(nmq[0]), int(nmq[1]), int(nmq[2])
mt = []
for i in range(0, n):
    mt.append([])
    for j in range(0, m):
        mt[-1].append((i, j))
res = []
for i in range(0, n):
    res.append([])
    for j in range(0, m):
        res[-1].append(0)
for i in range(0, q):
    ins = input().split(' ')
    if ins[0] == '1':
        r = int(ins[1]) - 1
        b = mt[r][0]
        for j in range(0, m-1):
            mt[r][j] = mt[r][j+1]
        mt[r][m-1] = b
    if ins[0] == '2':
        c = int(ins[1]) - 1
        b = mt[0][c]
        for j in range(0, n-1):
            mt[j][c] = mt[j+1][c]
        mt[n-1][c] = b
    if ins[0] == '3':
        r = int(ins[1]) - 1
        c = int(ins[2]) - 1
        x = int(ins[3])
        p = mt[r][c]
        res[p[0]][p[1]] = x
for i in range(0, n):
    for j in range(0, m-1):
        print(res[i][j],' ', end='')
    print(res[i][-1])
    


def rotate_r(ar, row, n):
	ar[row] = ar[row][-n:] + ar[row][:-n]
	return ar

def rotate_c(ar, m, col):
	#c = ar[col][0]
	c = ar[m - 1][col]
	for i in range(m - 1, 0, -1):
	#for i in range(m - 1):
		ar[i][col] = ar[i - 1][col]
	#ar[col][m - 1] = c
	ar[0][col] = c
	return ar

def print_matr(ar, n):
	for i in range(n):
		print(*ar[i])		

ar2 = []	

n, m, q = list(map(int, input().split()))
#for i in range(n):
#	ar = list(map(int, input().split()))
#	ar2.append(ar)


query = [0 for i in range(q)]
rows = [0 for i in range(q)]
cols = [0 for i in range(q)]
nums = [0 for i in range(q)]

for i in range(q):
	ar = list(map(int, input().split()))
	query[i] = ar[0]
	if ar[0] == 3:
		rows[i] = ar[1] - 1
		cols[i] = ar[2] - 1
		nums[i] = ar[3]
	elif ar[0] == 1:
		rows[i] = ar[1] - 1
	else:
		cols[i] = ar[1] - 1

#print(query)
ans = [[0] * m for i in range(n)]

for i in range(q - 1, -1, -1):
	if query[i] == 3:
		ans[rows[i]][cols[i]] = nums[i]
		#print('\n')
		#print_matr(ans, n)
		#print("l", rows[i] + 1, cols[i] + 1)
		#print(i, nums[i])
	elif query[i] == 1:
		ans = rotate_r(ans, rows[i], 1)
		#print('\n')
		#print_matr(ans, n)
	else:
		ans = rotate_c(ans, n, cols[i])
		#print('\n')
		#print_matr(ans, n)

#row, n = map(int, input().split())

#print(rotate_r(ar2, 0, n))
print_matr(ans, n)
#ans = rotate_c(ans, n, 0)
#print_matr(ans, n)


n,m,q=(int(z) for z in input().split())
s=[]
res=[]
for i in range(n):
	res.append([0]*m)
for i in range(q):
	s.append([int(z) for z in input().split()])
while len(s)>0:
	if s[-1][0]==3:
		res[s[-1][1]-1][s[-1][2]-1]=s[-1][3]
	elif s[-1][0]==2:
		r=res[-1][s[-1][1]-1]
		for i in range(n-1,0,-1):
			res[i][s[-1][1]-1]=res[i-1][s[-1][1]-1]
		res[0][s[-1][1]-1]=r
	else:
		r=res[s[-1][1]-1][-1]
		for i in range(m-1,0,-1):
			res[s[-1][1]-1][i]=res[s[-1][1]-1][i-1]
		res[s[-1][1]-1][0]=r
	s.pop()
for i in range(n):
	print(' '.join(map(str,res[i])))

a, b, c = map(int, input().split())
arr = []
mat = [[0 for j in range(b)] for i in range(a)]
for i in range(c):
    arr.append(input())
arr = arr[::-1]
for command in arr:
    arra = [int(i) for i in command.split()]
    if arra[0] == 1:
        swp = mat[arra[1] - 1][b - 1]
        for i in range(b):
            mat[arra[1] - 1][i], swp = swp, mat[arra[1] - 1][i]
    elif arra[0] == 2:
        swp = mat[a - 1][arra[1] - 1]
        for i in range(a):
            mat[i][arra[1] - 1], swp = swp, mat[i][arra[1] - 1]
    else:
        mat[arra[1] - 1][arra[2] - 1] = arra[3]
for i in mat:
    for j in i:
        print(j, end=" ")
    print()

m,n,q = map(int,input().split())
inps = [map(lambda x: int(x)-1,input().split()) for _ in range(q)]
matrix = [[-1]*n for _ in range(m)]
for x in reversed(inps):
    t,c,*cc = x
    if t == 0:
        matrix[c] = [matrix[c][-1]] + matrix[c][:-1]
    elif t == 1:
        new = [matrix[i][c] for i in range(m)]
        for i,x in enumerate([new[-1]] + new[:-1]):
            matrix[i][c] = x
    elif t == 2:
        matrix[c][cc[0]] = cc[1]
for x in matrix:
    print(' '.join(map(lambda v: str(v+1), x)))

n, m, q = map(int, input().split())
queries = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(q)]
matrix = [[0]*m for i in range(n)]
while queries:
    query = queries.pop()
    if query[0] == 0:
        row = [matrix[query[1]][-1]]
        row.extend(matrix[query[1]][:-1])
        matrix[query[1]] = row
    elif query[0] == 1:
        cell = matrix[n-1][query[1]]
        for i in range(n):
            matrix[i][query[1]], cell = cell, matrix[i][query[1]]
    else:
        matrix[query[1]][query[2]] = query[3] + 1
[print(*row) for row in matrix]


def main():
    n, m, q = list(map(int, input().split()))
    nm = ["0"] * (m * n)
    qq = [input() for _ in range(q)]
    for s in reversed(qq):
        k, *l = s.split()
        if k == "3":
            nm[(int(l[0]) - 1) * m + int(l[1]) - 1] = l[2]
        elif k == "2":
            j = int(l[0]) - 1
            x = nm[j - m]
            for i in range((n - 1) * m + j, j, -m):
                nm[i] = nm[i - m]
            nm[j] = x
        else:
            j = (int(l[0]) - 1) * m
            x = nm[j + m - 1]
            for i in range(j + m - 1, j, -1):
                nm[i] = nm[i - 1]
            nm[j] = x
    for i in range(0, n * m, m):
        print(' '.join(nm[i:i + m]))


def __starting_point():
    main()

__starting_point()

n, m, q = map(int, input().split())
nm = ["0"] * (m * n)
qq = [input() for _ in range(q)]
for s in reversed(qq):
    k, *l = s.split()
    if k == "3":
        nm[(int(l[0]) - 1) * m + int(l[1]) - 1] = l[2]
    elif k == "2":
        j = int(l[0]) - 1
        x = nm[j - m]
        for i in range((n - 1) * m + j, j, -m):
            nm[i] = nm[i - m]
        nm[j] = x
    else:
        j = (int(l[0]) - 1) * m
        x = nm[j + m - 1]
        for i in range(j + m - 1, j, -1):
            nm[i] = nm[i - 1]
        nm[j] = x
for i in range(0, n * m, m):
    print(' '.join(nm[i:i + m]))

f = lambda: map(int, input().split())
n, m, q = f()
p = [[0] * m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
    j = t[1] - 1
    if t[0] == 1: p[j].insert(0, p[j].pop())
    elif t[0] == 2: 
        s = p[-1][j]
        for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]
        p[0][j] = s
    else: p[j][t[2] - 1] = t[3]
for d in p: print(*d)

f = lambda: list(map(int, input().split()))
n, m, q = f()
p = [[0] * m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
    j = t[1] - 1
    if t[0] == 1: p[j].insert(0, p[j].pop())
    elif t[0] == 2: 
        s = p[-1][j]
        for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]
        p[0][j] = s
    else: p[j][t[2] - 1] = t[3]
for d in p: print(*d)


f = lambda: list(map(int, input().split()))

n, m, q = f()

p = [[0] * m for j in range(n)]

for t in [list(f()) for k in range(q)][::-1]:

    j = t[1] - 1

    if t[0] == 1: p[j].insert(0, p[j].pop())

    elif t[0] == 2: 

        s = p[-1][j]

        for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]

        p[0][j] = s

    else: p[j][t[2] - 1] = t[3]

for d in p: print(*d)




# Made By Mostafa_Khaled