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 ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m,  - 109 ≤ xi ≤ 109) are given.

Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.

Output

Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 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: MEDIUM
Tags: Implementation

Starter code:

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


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


from copy import copy
(n, m, q) = map(int, input().split())
mat = [[1 for i in range(m + 1)] for j in range(n + 1)]
op = []
for i in range(q):
	op.append(list(map(int, input().split())))
for i in range(q - 1, -1, -1):
	__type = op[i][0]
	if __type == 1:
		row = op[i][1]
		row -= 1
		temp = copy(mat[row][m - 1])
		for j in range(m - 1, 0, -1):
			mat[row][j] = copy(mat[row][j - 1])
		mat[row][0] = copy(temp)
	elif __type == 2:
		col = op[i][1]
		col -= 1
		temp = copy(mat[n - 1][col])
		for j in range(n - 1, 0, -1):
			mat[j][col] = copy(mat[j - 1][col])
		mat[0][col] = copy(temp)
	elif __type == 3:
		(row, col, val) = op[i][1:4]
		row -= 1
		col -= 1
		mat[row][col] = val
for i in range(n):
	s = ''
	for j in range(m):
		s += str(mat[i][j]) + ' '
	print(s)


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)


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


(n, m, q) = map(int, input().split())
mass = []
for i in range(q):
	mass.insert(0, list(map(int, input().split())))
matrix = [[0] * m for i in range(n)]
for i in range(q):
	if mass[i][0] == 3:
		matrix[mass[i][1] - 1][mass[i][2] - 1] = mass[i][3]
	elif mass[i][0] == 1:
		tmp = matrix[mass[i][1] - 1][m - 1]
		for j in range(m - 1, 0, -1):
			matrix[mass[i][1] - 1][j] = matrix[mass[i][1] - 1][j - 1]
		matrix[mass[i][1] - 1][0] = tmp
	else:
		tmp = matrix[n - 1][mass[i][1] - 1]
		for k in range(n - 1, 0, -1):
			matrix[k][mass[i][1] - 1] = matrix[k - 1][mass[i][1] - 1]
		matrix[0][mass[i][1] - 1] = tmp
for i in range(n):
	print(' '.join(list(map(str, matrix[i]))))


(n, m, q) = [int(i) for i in input().split()]
s = [[0 for i in range(m)] for i in range(n)]
a = []
b = []
c = []
d = []
for i in range(q):
	o = [int(i) for i in input().split()]
	d.append(o[0])
	if o[0] == 1:
		a.append(o[1] - 1)
	if o[0] == 2:
		b.append(o[1] - 1)
	if o[0] == 3:
		c.append(o[1:])
for i in d[::-1]:
	if i == 3:
		s[c[-1][0] - 1][c[-1][1] - 1] = c[-1][2]
		c.pop()
	if i == 2:
		y = s[-1][b[-1]]
		for j in range(n - 1, 0, -1):
			s[j][b[-1]] = s[j - 1][b[-1]]
		s[0][b[-1]] = y
		b.pop()
	if i == 1:
		s[a[-1]] = [s[a[-1]][-1]] + s[a[-1]][:-1]
		a.pop()
for i in range(n):
	print(*s[i])


(n, m, q) = map(int, input().split())
res = [0] * int(10000.0 + 5)
arr = list(([0] * (m + 1) for _ in range(n + 1)))

def shift_row(r):
	arr[r][m] = arr[r][m - 1]
	for i in range(m - 1, 0, -1):
		arr[r][i] = arr[r][i - 1]
	arr[r][0] = arr[r][m]

def shift_col(c):
	arr[n][c] = arr[n - 1][c]
	for i in range(n - 1, 0, -1):
		arr[i][c] = arr[i - 1][c]
	arr[0][c] = arr[n][c]
for i in range(q):
	qi = list(map(int, input().split()))
	if qi[0] == 3:
		res[i] = ((qi[0], qi[3]), (qi[1], qi[2]))
	else:
		res[i] = ((qi[0], qi[1]), (-1, -1))
for i in range(q - 1, -1, -1):
	if res[i][0][0] == 3:
		arr[res[i][1][0] - 1][res[i][1][1] - 1] = res[i][0][1]
	elif res[i][0][0] == 1:
		shift_row(res[i][0][1] - 1)
	elif res[i][0][0] == 2:
		shift_col(res[i][0][1] - 1)
for i in range(n):
	print(*arr[i][:-1])


def C():
	d = input().split(' ')
	n = int(d[0])
	m = int(d[1])
	s = int(d[2])
	z = []
	matr = []
	for i in range(n):
		cur = []
		for j in range(m):
			cur.append(0)
		matr.append(cur)
	for i in range(s):
		zapr = []
		cur = input().split(' ')
		zapr = list(map(int, cur))
		z.append(zapr)
	for i in range(s):
		a = z[s - i - 1]
		if a[0] == 1:
			matr = shift_r(matr, a[1] - 1, m)
		if a[0] == 2:
			matr = shift_d(matr, a[1] - 1, n)
		if a[0] == 3:
			matr[a[1] - 1][a[2] - 1] = a[3]
	for i in range(n):
		cur = ''
		for j in range(m):
			cur += str(matr[i][j]) + ' '
		print(cur)

def shift_r(mm, pos=0, n=0):
	curr = int(mm[pos][-1])
	for i in range(n - 1):
		mm[pos][n - i - 1] = mm[pos][n - i - 2]
	mm[pos][0] = curr
	return mm

def shift_d(mm, pos=0, n=0):
	curr = int(mm[-1][pos])
	for i in range(n - 1):
		mm[n - i - 1][pos] = mm[n - i - 2][pos]
	mm[0][pos] = curr
	return mm
C()


import sys
import math
import itertools as it
import operator as op
import fractions as fr
(n, m, q) = map(int, sys.stdin.readline().split())
A = [[r * m + c for c in range(m)] for r in range(n)]
V = [0 for i in range(n * m)]
for _ in range(q):
	L = list(map(int, sys.stdin.readline().split()))
	if L[0] == 1:
		r = L[1]
		r -= 1
		A[r] = A[r][1:] + A[r][:1]
	elif L[0] == 2:
		c = L[1]
		c -= 1
		e = A[0][c]
		for i in range(1, n):
			A[i - 1][c] = A[i][c]
		A[n - 1][c] = e
	else:
		(r, c, v) = L[1:]
		r -= 1
		c -= 1
		V[A[r][c]] = v
for r in range(n):
	print(' '.join(map(str, V[r * m:(r + 1) * m])))


(n, m, q) = map(int, input().split())
mat = [[(i, j) for j in range(m)] for i in range(n)]
M = [[0 for j in range(m)] for i in range(n)]
for _ in range(q):
	qry = list(map(int, input().split()))
	if qry[0] == 1:
		i = qry[1] - 1
		mat[i] = mat[i][1:] + [mat[i][0]]
	elif qry[0] == 2:
		j = qry[1] - 1
		fst = mat[0][j]
		for i in range(n - 1):
			mat[i][j] = mat[i + 1][j]
		mat[n - 1][j] = fst
	else:
		x = qry[1] - 1
		y = qry[2] - 1
		M[mat[x][y][0]][mat[x][y][1]] = qry[3]
for row in M:
	print(' '.join(list(map(str, row))))


from queue import LifoQueue
parse_int = lambda : list(map(int, input().split()))
(n, m, q) = parse_int()
mtx = [[0 for _2 in range(m)] for _1 in range(n)]

def shift(l):
	return [l[_ % len(l)] for _ in range(-1, len(l) - 1)]

def col_shift(col):
	global mtx
	col -= 1
	COL = shift([mtx[row][col] for row in range(n)])
	for row in range(n):
		mtx[row][col] = COL[row]

def row_shift(row):
	global mtx
	row -= 1
	mtx[row] = shift(mtx[row])

def assign(row, col, value):
	(row, col) = (row - 1, col - 1)
	mtx[row][col] = value
com = {1: lambda a: row_shift(a), 2: lambda b: col_shift(b), 3: lambda x, y, z: assign(x, y, z)}
stack = LifoQueue()
for _ in range(q):
	stack.put(parse_int())
for _ in range(q):
	inp = stack.get()
	if len(inp) == 2:
		com[inp[0]](inp[1])
	else:
		com[inp[0]](inp[1], inp[2], inp[3])
for row in mtx:
	for elem in row:
		print(elem, end=' ')
	print()


import unittest
import sys

class Matrix:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.m, self.q] = map(int, uinput().split())
		self.nums = []
		for i in range(self.q):
			self.nums.append(list(map(int, uinput().split())))

	def calculate(self):
		matrix = []
		for r in range(self.n):
			row = [0] * self.m
			matrix.append(row)
		for cmd in reversed(self.nums):
			if cmd[0] == 3:
				matrix[cmd[1] - 1][cmd[2] - 1] = cmd[3]
			elif cmd[0] == 1:
				rep = matrix[cmd[1] - 1][-1]
				for i in range(self.m):
					(matrix[cmd[1] - 1][i], rep) = (rep, matrix[cmd[1] - 1][i])
			elif cmd[0] == 2:
				rep = matrix[-1][cmd[1] - 1]
				for i in range(self.n):
					(matrix[i][cmd[1] - 1], rep) = (rep, matrix[i][cmd[1] - 1])
		rows = [' '.join(map(str, row)) for row in matrix]
		result = '\n'.join(rows)
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8'
		d = Matrix(test)
		self.assertEqual(d.n, 2)
		self.assertEqual(d.m, 2)
		self.assertEqual(d.q, 6)
		self.assertEqual(d.nums[0], [2, 1])
		self.assertEqual(Matrix(test).calculate(), '8 2\n1 8')
		test = '3 3 2\n1 2\n3 2 2 5'
		self.assertEqual(Matrix(test).calculate(), '0 0 0\n0 0 5\n0 0 0')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Matrix(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Matrix().calculate())


def w(ind):
	global mtx, n, m
	box = mtx[ind][-1]
	for i in range(m - 1 - 1, -1, -1):
		mtx[ind][i + 1] = mtx[ind][i]
	mtx[ind][0] = box

def h(ind):
	global mtx, n, m
	box = mtx[-1][ind]
	for i in range(n - 1 - 1, -1, -1):
		mtx[i + 1][ind] = mtx[i][ind]
	mtx[0][ind] = box
global mtx, n, m
(n, m, q) = [int(i) for i in input().split()]
mtx = [[0 for i in range(m)] for j in range(n)]
data = [[] for i in range(q)]
for i in range(q):
	data[q - i - 1] = [int(j) for j in input().split()]
p = 0
for i in data:
	cmd = i[0]
	ind = 0
	(x, y) = (0, 0)
	box = 0
	if p and cmd == 1:
		ind = i[1] - 1
		w(ind)
	elif p and cmd == 2:
		ind = i[1] - 1
		h(ind)
	elif cmd == 3:
		(x, y) = (i[1] - 1, i[2] - 1)
		box = i[3]
		mtx[x][y] = box
		p = 1
for i in mtx:
	for j in i:
		print(j, end=' ')
	print()


def solve(n, m, data):
	res = []
	for x in range(n):
		res.append([0] * m)
	data2 = reversed(data)
	for y in data2:
		if y[0] == 1:
			tmp = res[y[1] - 1][-1]
			del res[y[1] - 1][-1]
			res[y[1] - 1].insert(0, tmp)
		elif y[0] == 2:
			k = y[1] - 1
			tmp = res[-1][k]
			for j in range(n - 1):
				res[-j - 1][k] = res[-j - 2][k]
			res[0][k] = tmp
		else:
			res[y[1] - 1][y[2] - 1] = y[3]
	return res
(n, m, q) = [int(x) for x in input().split()]
data = []
for i in range(q):
	data.append([int(x) for x in input().split()])
sol = solve(n, m, data)
for x in sol:
	for y in x[:-1]:
		print(y, end=' ')
	print(x[-1])


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


(n, m, q) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(q)][::-1]
adj = [[0] * m for _ in range(n)]
for i in range(q):
	t = l[i]
	if t[0] == 3:
		adj[t[1] - 1][t[2] - 1] = t[3]
	elif t[0] == 2:
		j = t[1] - 1
		x = adj[-1][j]
		for i in range(n - 1, 0, -1):
			adj[i][j] = adj[i - 1][j]
		adj[0][j] = x
	else:
		adj[t[1] - 1] = [adj[t[1] - 1][-1]] + adj[t[1] - 1][:-1]
for x in adj:
	print(*x)


(n, m, qq) = map(int, input().split())
queries = []
for i in range(qq):
	queries.append(list(map(int, input().split())))
G = [[0] * m for i in range(n)]
for q in reversed(queries):
	if q[0] == 1:
		last = G[q[1] - 1][-1]
		for j in range(m - 2, -1, -1):
			G[q[1] - 1][j + 1] = G[q[1] - 1][j]
		G[q[1] - 1][0] = last
	if q[0] == 2:
		last = G[-1][q[1] - 1]
		for j in range(n - 2, -1, -1):
			G[j + 1][q[1] - 1] = G[j][q[1] - 1]
		G[0][q[1] - 1] = last
	if q[0] == 3:
		G[q[1] - 1][q[2] - 1] = q[3]
for i in range(n):
	print(*G[i])


(n, m, q) = [int(x) for x in input().split()]
L = []
for i in range(q):
	L.append([int(x) - 1 for x in input().split()])
L = L[::-1]
ar = [[1] * m for i in range(n)]
for i in L:
	if i[0] is 2:
		ar[i[1]][i[2]] = i[3] + 1
	elif i[0] is 1:
		col = i[1]
		x = ar[n - 1][col]
		for j in range(n - 1, 0, -1):
			ar[j][col] = ar[j - 1][col]
		ar[0][col] = x
	else:
		row = i[1]
		ar[row] = [ar[row][m - 1]] + ar[row][:m - 1]
for i in ar:
	print(' '.join(map(str, i)))


def func1(l):
	per = A[l - 1][m - 1]
	for i in range(m - 2, -1, -1):
		A[l - 1][i + 1] = A[l - 1][i]
	A[l - 1][0] = per

def func2(r):
	per = A[-1][r - 1]
	for i in range(n - 2, -1, -1):
		A[i + 1][r - 1] = A[i][r - 1]
	A[0][r - 1] = per
(n, m, q) = map(int, input().split())
B = [0] * q
for i in range(q):
	B[i] = list(map(int, input().split()))
A = ['0'] * n
for i in range(n):
	A[i] = [0] * m
for i in range(q - 1, -1, -1):
	if B[i][0] == 3:
		A[B[i][1] - 1][B[i][2] - 1] = B[i][3]
	elif B[i][0] == 2:
		func2(B[i][1])
	else:
		func1(B[i][1])
for i in range(n):
	print(' '.join(map(str, A[i])))


(n, m, q) = map(int, input().split())
queries = list()
for i in range(q):
	query = list(map(int, input().split()))
	queries.append(query)
arr = [[0 for i in range(m)] for j in range(n)]
queries = queries[::-1]
for query in queries:
	x = query[0]
	if x <= 2:
		y = query[1]
		if x == 1:
			r = arr[y - 1].pop()
			arr[y - 1].insert(0, r)
		else:
			temp = [arr[i][y - 1] for i in range(n)]
			r = temp.pop()
			temp.insert(0, r)
			for i in range(n):
				arr[i][y - 1] = temp[i]
	else:
		(a, b, c) = query[1:]
		arr[a - 1][b - 1] = c
for i in range(n):
	for j in range(m):
		print(arr[i][j], end=' ')
	print()


import sys
sys.stderr = sys.stdout

def matrix(n, m, q, O):
	V = [0] * (n * m)
	M = [list(range(i0, i0 + m)) for i0 in range(0, n * m, m)]
	for o in O:
		if o[0] == 1:
			(t, r) = o
			r -= 1
			p = M[r][0]
			for j in reversed(range(m)):
				(p, M[r][j]) = (M[r][j], p)
		elif o[0] == 2:
			(t, c) = o
			c -= 1
			p = M[0][c]
			for i in reversed(range(n)):
				(p, M[i][c]) = (M[i][c], p)
		else:
			(t, r, c, x) = o
			r -= 1
			c -= 1
			V[M[r][c]] = x
	return [V[i0:i0 + m] for i0 in range(0, n * m, m)]

def main():
	(n, m, q) = readinti()
	O = readinttl(q)
	M = matrix(n, m, q, O)
	print('\n'.join((' '.join(map(str, M_i)) for M_i in M)))

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.__stderr__)
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)))


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


(n, m, q) = map(int, input().split())
pos = [0, 0]
a = []
for i in range(n):
	a.append([0] * m)
hist = [0] * q
for k in range(q):
	query = list(map(int, input().split()))
	if query[0] == 3:
		a[query[1] - 1][query[2] - 1] = query[3]
	elif query[0] == 1:
		r = query[1] - 1
		hist[k] = r + 1
		help = [0] * m
		for i in range(m - 1):
			help[i] = a[r][i + 1]
		help[m - 1] = a[r][0]
		for i in range(m):
			a[r][i] = help[i]
	else:
		x = query[1] - 1
		hist[k] = -(x + 1)
		help = [0] * n
		for i in range(n - 1):
			help[i] = a[i + 1][x]
		help[n - 1] = a[0][x]
		for i in range(n):
			a[i][x] = help[i]
for k in range(q - 1, -1, -1):
	if hist[k] > 0:
		r = hist[k] - 1
		help = [0] * m
		for i in range(m):
			help[i] = a[r][i - 1]
		for i in range(m):
			a[r][i] = help[i]
	elif hist[k] < 0:
		x = -hist[k] - 1
		help = [0] * n
		for i in range(n):
			help[i] = a[i - 1][x]
		for i in range(n):
			a[i][x] = help[i]
for i in a:
	print(' '.join(map(str, i)))


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


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


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


(n, m, q) = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
t = [[100 * i + j for j in range(m)] for i in range(n)]
ans = [[0 for _ in range(m)] for _ in range(n)]
for i in range(q):
	if Q[i][0] == 1:
		x = t[Q[i][1] - 1][0]
		for j in range(m - 1):
			t[Q[i][1] - 1][j] = t[Q[i][1] - 1][j + 1]
		t[Q[i][1] - 1][m - 1] = x
	elif Q[i][0] == 2:
		x = t[0][Q[i][1] - 1]
		for j in range(n - 1):
			t[j][Q[i][1] - 1] = t[j + 1][Q[i][1] - 1]
		t[n - 1][Q[i][1] - 1] = x
	else:
		x = t[Q[i][1] - 1][Q[i][2] - 1]
		ans[x // 100][x % 100] = Q[i][3]
for i in range(n):
	print(' '.join((str(j) for j in ans[i])))