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

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation


Solutions:
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)


def main():
	(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]))
main()


inf = list(map(int, input().split()))
n = inf[0]
m = inf[1]
q = inf[2]
quer = [0] * q
mat = [[0 for i in range(m)] for j in range(n)]
for i in range(0, q):
	quer[i] = list(map(int, input().split()))
for i in range(q - 1, -1, -1):
	curr = quer[i]
	if curr[0] == 1:
		x = curr[1] - 1
		a = mat[x][m - 1]
		for j in range(m - 1, 0, -1):
			mat[x][j] = mat[x][j - 1]
		mat[x][0] = a
	elif curr[0] == 2:
		x = curr[1] - 1
		a = mat[n - 1][x]
		for j in range(n - 1, 0, -1):
			mat[j][x] = mat[j - 1][x]
		mat[0][x] = a
	elif curr[0] == 3:
		mat[curr[1] - 1][curr[2] - 1] = curr[3]
for i in range(n):
	print(*mat[i])


(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 rotate_r(ar, row, n):
	ar[row] = ar[row][-n:] + ar[row][:-n]
	return ar

def rotate_c(ar, m, col):
	c = ar[m - 1][col]
	for i in range(m - 1, 0, -1):
		ar[i][col] = ar[i - 1][col]
	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()))
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
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]
	elif query[i] == 1:
		ans = rotate_r(ans, rows[i], 1)
	else:
		ans = rotate_c(ans, n, cols[i])
print_matr(ans, n)


(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()


(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])))


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])


import sys
import time
from pprint import pprint
from sys import stderr
from itertools import combinations
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9

def time_it(function, output=stderr):

	def wrapped(*args, **kwargs):
		start = time.time()
		res = function(*args, **kwargs)
		elapsed_time = time.time() - start
		print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000), file=output)
		return res
	return wrapped

@time_it
def main():
	(n, m, q) = map(int, input().split())
	matrix = [[(x, y) for x in range(m)] for y in range(n)]
	init_matrix = [[0] * m for _ in range(n)]
	for _ in range(q):
		args = list(map(int, input().split()))
		t = args[1] - 1
		if args[0] == 1:
			matrix[t] = matrix[t][1:] + matrix[t][:1]
		elif args[0] == 2:
			first = matrix[0][t]
			for i in range(n - 1):
				matrix[i][t] = matrix[i + 1][t]
			matrix[n - 1][t] = first
		else:
			r = args[2] - 1
			x = args[3]
			init_matrix[matrix[t][r][1]][matrix[t][r][0]] = x
	for row in init_matrix:
		print(*row)

def set_input(file):
	global input
	input = lambda : file.readline().strip()

def set_output(file):
	global print
	local_print = print

	def print(*args, **kwargs):
		kwargs['file'] = kwargs.get('file', file)
		return local_print(*args, **kwargs)
set_input(open('input.txt', 'r') if 'MINE' in sys.argv else sys.stdin)
set_output(sys.stdout)
main()


(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)))


import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def main():
	(n, m, q) = mii()
	qq = []
	for test in range(q):
		pp = lmii()
		qq.append(pp)
	qq.reverse()
	mat = []
	for i in range(n):
		mat.append([0] * m)
	for i in range(q):
		lst = qq[i]
		if lst[0] == 3:
			mat[lst[1] - 1][lst[2] - 1] = lst[3]
		elif lst[0] == 2:
			d = deque([])
			for k in range(n):
				d.append(mat[k][lst[1] - 1])
			d.appendleft(d.pop())
			for k in range(n):
				mat[k][lst[1] - 1] = d[k]
		else:
			d = deque([])
			for k in range(m):
				d.append(mat[lst[1] - 1][k])
			d.appendleft(d.pop())
			for k in range(m):
				mat[lst[1] - 1][k] = d[k]
	for i in range(n):
		print(*mat[i])
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()