Cherry has a binary matrix $A$ consisting of $N$ rows and $M$ columns. The rows are numbered from $1$ to $N$, columns are numbered from $1$ to $M$. Element at row $i$ ($1$ ≤ $i$ ≤ $N$) and column $j$ ($1$ ≤ $j$ ≤ $M$) is denoted as $A_{ij}$. All elements of $A$ are either $0$ or $1$.
He performs $Q$ queries on matrix. Each query is provided by four integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ which define the rectangle, where ($x_{1}$, $y_{1}$) stands for the coordinates of the top left cell of the rectangle, while ($x_{2}$, $y_{2}$) stands for the coordinates of the bottom right cell. You need to flip all the bits i.e. ($0$ to $1$, $1$ to $0$) that are located fully inside the query rectangle.
Finally, print the matrix after performing all the queries.
Note: $x_{1}$ represents the row number while $y_{1}$ represents the column number.

-----Input:-----
- The first line of the input contains two integers $N$ and $M$ — the number of rows and the number of columns in the matrix.
- Each of the next $N$ lines contains a string of length $M$, where the $j^{th}$ character of $i^{th}$ line denotes the value of $A_{i,j}$. 
- Next line contains an integer $Q$ — the number of queries.
- Then follow $Q$ lines with queries descriptions. Each of them contains four space-seperated integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ — coordinates of the up left and bottom right cells of the query rectangle.

-----Output:-----
Print the matrix, in the form of $N$ strings, after performing all the queries.

-----Constraints-----
- $1 \leq N,M \leq 1000$
- $0 \leq  A_{ij}  \leq 1$
- $1 \leq Q \leq 10^6$
- $1 \leq x_{1} \leq x_{2} \leq N$
- $1 \leq y_{1} \leq y_{2} \leq M$

-----Sample Input:-----
2 2
00
00
3
1 1 1 1
2 2 2 2
1 1 2 2 

-----Sample Output:-----
01
10

-----Explanation:-----
Example case 1:
After processing the 1st query 1 1 1 1, matrix becomes:
[1000][1000]\begin{bmatrix} 10 \\ 00  \end{bmatrix}
After processing the 2nd query 2 2 2 2, the matrix becomes:
[1001][1001]\begin{bmatrix} 10 \\ 01  \end{bmatrix}
After processing the 3rd query 1 1 2 2, matrix becomes:
[0110][0110]\begin{bmatrix} 01 \\ 10  \end{bmatrix}
We need to output the matrix after processing all queries.

Difficulty: interview

Starter code:

Solutions:
import sys,os,io,time,copy,math,queue,bisect
from collections import deque
from functools import lru_cache

if os.path.exists('input.txt'):
 sys.stdin = open('input.txt', 'r')
 sys.stdout = open('output.txt', 'w') 

sys.setrecursionlimit(100000000)

def main():
 n,m=map(int,input().split())
 mat=[]
 for _ in range(n):
  s=input()
  a=[]
  for i in s:
   a.append(int(i))
  mat.append(a)
  
 Q=int(input())
 ans=[[0 for i in range(m+1)] for j in range(n+1)]
 for i in range(Q):
  x1,y1,x2,y2=map(int,input().split())
  x1-=1
  y1-=1
  x2-=1
  y2-=1
  ans[x1][y1]+=1
  ans[x2+1][y1]-=1
  ans[x1][y2+1]-=1
  ans[x2+1][y2+1]+=1
 for j in range(m+1):
  for i in range(1,n+1):
   ans[i][j]=ans[i-1][j]+ans[i][j]
 for i in range(n+1):
  for j in range(1,m+1):
   ans[i][j]=ans[i][j-1]+ans[i][j]
 
 for i in range(n):
  for j in range(m):
   mat[i][j]=(ans[i][j]+mat[i][j])%2
 for m in mat:
  for i in m:
   print(i,end="")
  print("")

  
main()


# cook your dish here
def issafe(a,b,n,m):
 if(0<=a<n and 0<=b<m):
  return True
 return False
def main():
 n,m=map(int,input().split())
 mat=[list(map(int,list(input()))) for i in range(n)]
 qmat=[[0 for i in range(m)] for j in range(n)]
 q=int(input())
 query=[list(map(int,input().split())) for i in range(q)]
 for k in query:
  i1,j1,i2,j2=map(lambda x:x-1,k)
  qmat[i1][j1]+=1
  if(issafe(i2+1,j2+1,n,m)):
   qmat[i2+1][j2+1]+=1
  if(issafe(i1,j2+1,n,m)):
   qmat[i1][j2+1]+=-1
  if(issafe(i2+1,j1,n,m)):
   qmat[i2+1][j1]+=-1
 for i in range(n-1):
  for j in range(m):
   qmat[i+1][j]+=qmat[i][j]
 for i in range(n):
  for j in range(m-1):
   qmat[i][j+1]+=qmat[i][j]
 for i in range(n):
  for j in range(m):
   qmat[i][j]=(qmat[i][j]+mat[i][j])%2
 for i in qmat:
  print(*i,sep='')
main()

def issafe(a,b,n,m):
 if(0<=a<n and 0<=b<m):
  return True
 return False
def main():
 n,m=map(int,input().split())
 mat=[list(map(int,list(input()))) for i in range(n)]
 qmat=[[0 for i in range(m)] for j in range(n)]
 q=int(input())
 query=[list(map(int,input().split())) for i in range(q)]
 # print(query)
 for k in query:
  i1,j1,i2,j2=map(lambda x:x-1,k)
  qmat[i1][j1]+=1
  if(issafe(i2+1,j2+1,n,m)):
   qmat[i2+1][j2+1]+=1
  if(issafe(i1,j2+1,n,m)):
   qmat[i1][j2+1]+=-1
  if(issafe(i2+1,j1,n,m)):
   qmat[i2+1][j1]+=-1
 for i in range(n-1):
  for j in range(m):
   qmat[i+1][j]+=qmat[i][j]
 for i in range(n):
  for j in range(m-1):
   qmat[i][j+1]+=qmat[i][j]
 for i in range(n):
  for j in range(m):
   qmat[i][j]=(qmat[i][j]+mat[i][j])%2
 for i in qmat:
  print(*i,sep='')
main()
# import sys,threading
# max_recur_size = 10**5+ 10000
# max_stack_size = max_recur_size*500
# sys.setrecursionlimit(max_recur_size)
# threading.stack_size(max_stack_size)
# thread = threading.Thread(target=main)
# thread.start()

def issafe(a,b,n,m):
 if(0<=a<n and 0<=b<m):
  return True
 return False
def main():
 n,m=map(int,input().split())
 mat=[list(map(int,list(input()))) for i in range(n)]
 qmat=[[0 for i in range(m)] for j in range(n)]
 q=int(input())
 query=[list(map(int,input().split())) for i in range(q)]
 # print(query)
 for k in query:
  i1,j1,i2,j2=map(lambda x:x-1,k)
  qmat[i1][j1]+=1
  if(issafe(i2+1,j2+1,n,m)):
   qmat[i2+1][j2+1]+=1
  if(issafe(i1,j2+1,n,m)):
   qmat[i1][j2+1]+=-1
  if(issafe(i2+1,j1,n,m)):
   qmat[i2+1][j1]+=-1
 for i in range(n-1):
  for j in range(m):
   qmat[i+1][j]+=qmat[i][j]
 for i in range(n):
  for j in range(m-1):
   qmat[i][j+1]+=qmat[i][j]
 for i in range(n):
  for j in range(m):
   qmat[i][j]=(qmat[i][j]+mat[i][j])%2
 for i in qmat:
  print(*i,sep='')
main()
# import sys,threading
# max_recur_size = 10**5+ 10000
# max_stack_size = max_recur_size*500
# sys.setrecursionlimit(max_recur_size)
# threading.stack_size(max_stack_size)
# thread = threading.Thread(target=main)
# thread.start()

# -*- coding: utf-8 -*-
"""
@author: coding_don
"""
import sys
#sys.stdin = open('ip.txt', 'r') 
#sys.stdout = open('op.txt', 'w')
try:
 
 def main():
  t=1
  # t=int(sys.stdin.readline())
  while(t):
   n,m=[int(x) for x in sys.stdin.readline().split()]
   a=[]
   update=[]
   for i in range(n):
    tmp=sys.stdin.readline()
    a.append(tmp)
    update.append([0 for j in range(m+1)])
   update.append([0 for j in range(m+1)])
   q=int(sys.stdin.readline())
   while(q):
    x1,y1,x2,y2=[int(z) for z in sys.stdin.readline().split()]
    update[x1][y1]+=1
    if(x2<n):
     update[x2+1][y1]+=-1
    if(y2<m):
     update[x1][y2+1]+=-1
    if(x2<n and y2<m):
     update[x2+1][y2+1]+=1
   
    q-=1

   for i in range(1,n+1):
    for j in range(1,m+1):
     update[i][j]+=update[i][j-1]

   for j in range(1,m+1):
    for i in range(1,n+1):
     update[i][j]+=update[i-1][j]
   for i in range(1,n+1):
    for j in range(1,m+1):
     if(update[i][j]%2==0):
      sys.stdout.write(a[i-1][j-1])
     else:
      sys.stdout.write(str(1-(ord(a[i-1][j-1])-48)))

    sys.stdout.write('\n')

   t-=1
  
 main()
  
except Exception as e:
 sys.stdout.write("ErrOR : "+str(e))

# cook your dish here
def flip(dp,x1,y1,x2,y2,n,m):
 dp[x1][y1] += 1
  
 if y2+1 < m:
  dp[x1][y2+1] -= 1

 if x2+1 < n:
  dp[x2+1][y1] -= 1

 if x2+1 < n and y2+1 < m:
  dp[x2+1][y2+1] += 1

def main():
 n,m = map(int,input().split())
 matrix = []
 for i in range(n):
  matrix.append(list(map(int,input())))


 dp = [[0 for j in range(m)] for i in range(n)]
 q = int(input())
 for i in range(q):
  x1,y1,x2,y2 = map(int,input().split())
  x1 -= 1
  y1 -= 1
  x2 -= 1
  y2 -= 1
  flip(dp,x1,y1,x2,y2,n,m)

 for i in range(n):
  for j in range(1,m):
   dp[i][j] += dp[i][j-1]

 for i in range(1,n):
  for j in range(m):
   dp[i][j] += dp[i-1][j]

 for i in range(n):
  for j in range(m):
   if dp[i][j]%2 == 0:
    print(matrix[i][j],end = '')
   else:
    print(int(not matrix[i][j]),end = '')

  print()

main()


r,c=list(map(int,input().split()))
A=[] #Given Matrix
dp=[[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
 A.append([int(j) for j in list(input())])
 #print(A)

q=int(input())

#print(A,dp)
for i in range(q):
 x1,y1,x2,y2=list(map(int,input().split()))
 #print(x1,y1,x2,y2)
 x1,y1,x2,y2=x1-1,y1-1,x2-1,y2-1
 dp[x1][y1]+=1
 dp[x2+1][y2+1]+=1
 dp[x1][y2+1]-=1
 dp[x2+1][y1]-=1

for i,v1 in enumerate(A):
 for j,v2 in enumerate(v1):
  if i==0 and j==0:
   pass
  elif i==0:
   dp[i][j]+=dp[i][j-1]
  elif j==0:
   dp[i][j]+=dp[i-1][j]
  else:
   dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
  #print(A,i,j)

  if dp[i][j]%2!=0:
   A[i][j]=1-A[i][j]
for i in A:
 for j in i:
  print(j,end="")
 print()




import sys
 
n, m = map(int, sys.stdin.readline().strip().split())
 
arr = []
for i in range(n):
 s = input() + "0"
 temp = []
 for x in s:
  temp += [int(x)]
 arr += [temp]
 
arr += [[0]*(m+1)]
 
add = [[0 for i in range(m+1)] for j in range(n+1)]
pref1 = [[0 for i in range(m+1)] for j in range(n+1)]
pref2 = [[0 for i in range(m+1)] for j in range(n+1)]
 
q = int(sys.stdin.readline().strip())
for _ in range(q):
 x1, y1, x2, y2 = map(int, sys.stdin.readline().strip().split())
 x1 -= 1
 y1 -= 1
 x2 -= 1
 y2 -= 1
 pref2[x1][y1] += 1
 pref2[x2+1][y1] -= 1
 pref2[x1][y2+1] += -1
 pref2[x2+1][y2+1] -= -1
 
for i in range(m):
 for j in range(n):
  if j == 0:
   pref1[j][i] = pref2[j][i]
  else:
   pref1[j][i] = pref1[j-1][i] + pref2[j][i]
 
for i in range(n):
 for j in range(m):
  if j == 0:
   add[i][j] += pref1[i][j]
  else:
   add[i][j] = add[i][j-1] + pref1[i][j]
 
for i in range(n):
 for j in range(m):
  arr[i][j] += add[i][j]
  arr[i][j] %= 2
 
for i in range(n):
 for j in range(m):
  print(arr[i][j], end='')
 print('')


n,m=map(int,input().split())
mat=[]
for _ in range(n):
 s=input()
 l=list(map(int,s))
 mat.append(l)
pref=[[0 for _ in range(m+1)] for _ in range(n+1)]
p=[[0 for _ in range(m)] for _ in range(n)]
add=[[0 for _ in range(m)] for _ in range(n)]
for _ in range(int(input())):
 x1,y1,x2,y2=map(int,input().split())
 pref[x1-1][y1-1]+=1
 pref[x2][y1-1]-=1
 pref[x1-1][y2]-=1
 pref[x2][y2]+=1
for i in range(n):
 for j in range(m):
  if i==0:
   p[i][j]=pref[i][j]
  else:
   p[i][j]=p[i-1][j]+pref[i][j]
for i in range(n):
 for j in range(m):
  if j==0:
   add[i][j]=p[i][j]
  else:
   add[i][j]=add[i][j-1]+p[i][j]
for i in range(n):
 for j in range(m):
  mat[i][j]+=add[i][j]
  mat[i][j]%=2
for i in range(n):
 for j in range(m):
  print(mat[i][j],end="")
 print()


n, m = map(int, input().split())
a = []
b = [0] * (m + 1)
for i in range(n + 1):
 a.append(b[:])
# print(a[n - 1][m])
# print(a[1][2])
# print(a)
p = []
for i in range(n):
 r = input()
 q = []
 for j in range(len(r)):
  q.append(int(r[j]))
 p.append(q[:])
# print(p)
q = int(input())
while(q):
 i, j, k, l = map(int, input().split())
 a[i - 1][j - 1] += 1
 a[i - 1][l] -= 1
 a[k][j - 1] -= 1
 # print(k - 1, l)
 a[k][l] += 1
 q -= 1
c = 0
# print(a)
for j in range(m + 1):
 for i in range(n + 1):
  c += a[i][j]
  a[i][j] = c

for i in range(n):
 for j in range(m):
  c += a[i][j]
  if(c % 2 == 1):
   if(p[i][j] == 1):
    p[i][j] = 0
   else:
    p[i][j] = 1
 c += a[i][m]
# print(a)
for i in range(n):
 for j in range(m):
  print(p[i][j], end="")
 print()


# cook your dish here
import sys
 
n, m = map(int, sys.stdin.readline().strip().split())
 
arr = []
for i in range(n):
 s = input() + "0"
 temp = []
 for x in s:
  temp += [int(x)]
 arr += [temp]
 
arr += [[0]*(m+1)]
 
add = [[0 for i in range(m+1)] for j in range(n+1)]
pref1 = [[0 for i in range(m+1)] for j in range(n+1)]
pref2 = [[0 for i in range(m+1)] for j in range(n+1)]
 
q = int(sys.stdin.readline().strip())
for _ in range(q):
 x1, y1, x2, y2 = map(int, sys.stdin.readline().strip().split())
 x1 -= 1
 y1 -= 1
 x2 -= 1
 y2 -= 1
 pref2[x1][y1] += 1
 pref2[x2+1][y1] -= 1
 pref2[x1][y2+1] += -1
 pref2[x2+1][y2+1] -= -1
 
for i in range(m):
 for j in range(n):
  if j == 0:
   pref1[j][i] = pref2[j][i]
  else:
   pref1[j][i] = pref1[j-1][i] + pref2[j][i]
 
for i in range(n):
 for j in range(m):
  if j == 0:
   add[i][j] += pref1[i][j]
  else:
   add[i][j] = add[i][j-1] + pref1[i][j]
 
for i in range(n):
 for j in range(m):
  arr[i][j] += add[i][j]
  arr[i][j] %= 2
 
for i in range(n):
 for j in range(m):
  print(arr[i][j], end='')
 print('')


import sys
 
n, m = map(int, sys.stdin.readline().strip().split())
 
arr = []
for i in range(n):
 s = input() + "0"
 temp = []
 for x in s:
  temp += [int(x)]
 arr += [temp]
 
arr += [[0]*(m+1)]
 
add = [[0 for i in range(m+1)] for j in range(n+1)]
pref1 = [[0 for i in range(m+1)] for j in range(n+1)]
pref2 = [[0 for i in range(m+1)] for j in range(n+1)]
 
q = int(sys.stdin.readline().strip())
for _ in range(q):
 x1, y1, x2, y2 = map(int, sys.stdin.readline().strip().split())
 x1 -= 1
 y1 -= 1
 x2 -= 1
 y2 -= 1
 pref2[x1][y1] += 1
 pref2[x2+1][y1] -= 1
 pref2[x1][y2+1] += -1
 pref2[x2+1][y2+1] -= -1
 
for i in range(m):
 for j in range(n):
  if j == 0:
   pref1[j][i] = pref2[j][i]
  else:
   pref1[j][i] = pref1[j-1][i] + pref2[j][i]
 
for i in range(n):
 for j in range(m):
  if j == 0:
   add[i][j] += pref1[i][j]
  else:
   add[i][j] = add[i][j-1] + pref1[i][j]
 
for i in range(n):
 for j in range(m):
  arr[i][j] += add[i][j]
  arr[i][j] %= 2
 
for i in range(n):
 for j in range(m):
  print(arr[i][j], end='')
 print('')


import sys
import bisect
#input=sys.stdin.readline
#t=int(input())
t=1
for _ in range(t):
 n,m=map(int,input().split())
 #n=int(input())
 l=[]
 #l=list(map(int,input().split()))
 arr=[[0 for j in range(m+2)] for i in range(n+2)]
 for i in range(n):
  l.append(input())
 #print(arr)        
 q=int(input())
 for __ in range(q):
  x1,y1,x2,y2=map(int,input().split())
  arr[x1][y1]+=1;
  arr[x2+1][y1]-=1
  arr[x1][y2+1]-=1
  arr[x2+1][y2+1]+=1
 for i in range(1,n+1):
  for j in range(1,m+1):
   x1=(arr[i-1][j]+arr[i][j-1])
   y1=(x1-arr[i-1][j-1])
   arr[i][j]=(arr[i][j]+y1)
   
   #arr[i][j]%=2
   print((arr[i][j]+int(l[i-1][j-1]))%2,end="")
  print() 
 print() 
  

n,m=map(int,input().split())
mat=[]
for i in range(n):
 me=[int(i) for i in list(input())]
 mat.append(me)
dummy=[[0 for i in range(m+1)] for j in range(n+1)]
q=int(input())
for i in range(q):
 x1,y1,x2,y2=map(int,input().split())
 dummy[x1-1][y1-1]+=1
 dummy[x2][y1-1]-=1 
 dummy[x2][y2]+=1 
 dummy[x1-1][y2]-=1
for i in range(n+1):
 for j in range(m+1):
  if j==0:
   continue
  else:
   dummy[i][j]+=dummy[i][j-1]
for j in range(m+1): 
 for i in range(n+1): 
  if i==0:
   continue 
  else:
   dummy[i][j]+=dummy[i-1][j]
for i in range(n):
 for j in range(m):
  print((mat[i][j]+dummy[i][j]+2)%2,end="")
 print()
print()


n,m= map(int,input().split())
MX=list()
for i in range(n):
 YYY=str(input())
 yy=list(YYY)
 a=[]
 for j in range(m):
  a.append(yy[j])
 MX.append(a)

q=int(input())
dp=[[0 for i in range(m)]for i in range(n)]
for _ in range(q):
 x,y,x2,y2=map(int,input().split())
 dp[x-1][y-1]+=1
 if x2<n:
  dp[x2][y-1]-=1
 if y2<m:
  dp[x-1][y2]-=1
 if x2<n and y2<m:
  dp[x2][y2]-=1


for i in range(n):
 for j in range(1,m):
  dp[i][j]+=dp[i][j-1]

for i in range(m):
 for j in range(1,n):
  dp[j][i]+=dp[j-1][i]

# print(dp)
# print(MX)
for i in range(n):
 for j in range(m):
  if dp[i][j]%2==1:
   if MX[i][j]=='0':
    MX[i][j]='1'
   else:
    MX[i][j]='0'

  

for i in range(n):
 for j in range(m):
   print(MX[i][j],end="")

 print()


import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
import math
from collections import defaultdict

n, m = get_ints()
a = []
arr = [[0 for _ in range(m+2)] for _ in range(n+2)]
for _ in range(n):
  # t = get_array()
 t = list(input())
 # t.append('0')
 a.append(t)

for i in range(n):
 for j in range(m):
  a[i][j] = int(a[i][j])

# print(a)
# print(arr)


q = int(input())
for _ in range(q):
 x1,y1,x2,y2 = get_ints()
 # x1-=1
 # y1-=1
 # x2-=1
 # y2-=1
 arr[x1][y1]+=1
 arr[x2+1][y2+1]+=1
 arr[x1][y2 + 1]-=1
 arr[x2 + 1][y1]-=1

# print("hello ",arr)

for i in range(1,n+1):
 for j in range(1,m+1):
  arr[i][j] += arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1]
  if(a[i-1][j-1] == 0 and arr[i][j]%2==0):
   a[i-1][j-1] = 0
  elif(a[i-1][j-1] == 1 and arr[i][j]%2 == 0):
   a[i-1][j-1] = 1
  elif(a[i-1][j-1] == 0 and arr[i][j]%2==1):
   a[i-1][j-1] = 1
  elif(a[i-1][j-1] == 1 and arr[i][j]%2==1):
   a[i-1][j-1] = 0

# print(arr)
# print(a)

# for i in range(n):
#     for j in range(m):
#         print(a[i][j],end = "")
#     print()

for i in range(n):
 print(''.join(map(str,a[i])))






import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
import math
from collections import defaultdict

n, m = get_ints()
a = []
arr = [[0 for _ in range(m+2)] for _ in range(n+2)]
for _ in range(n):
  # t = get_array()
 t = list(input())
 # t.append('0')
 a.append(t)

for i in range(n):
 for j in range(m):
  a[i][j] = int(a[i][j])

# print(a)
# print(arr)


q = int(input())
for _ in range(q):
 x1,y1,x2,y2 = get_ints()
 # x1-=1
 # y1-=1
 # x2-=1
 # y2-=1
 arr[x1][y1]+=1
 arr[x2+1][y2+1]+=1
 arr[x1][y2 + 1]-=1
 arr[x2 + 1][y1]-=1

# print("hello ",arr)

for i in range(1,n+1):
 for j in range(1,m+1):
  arr[i][j] += arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1]
  if(a[i-1][j-1] == 0 and arr[i][j]%2==0):
   a[i-1][j-1] = 0
  elif(a[i-1][j-1] == 1 and arr[i][j]%2 == 0):
   a[i-1][j-1] = 1
  elif(a[i-1][j-1] == 0 and arr[i][j]%2==1):
   a[i-1][j-1] = 1
  elif(a[i-1][j-1] == 1 and arr[i][j]%2==1):
   a[i-1][j-1] = 0

# print(arr)
# print(a)

for i in range(n):
 for j in range(m):
  print(a[i][j],end = "")
 print()

# for i in range(n):
#     print(''.join(map(str,a[i])))






import sys
n,m=map(int,input().split())
dp=[[0 for j in range(m+2)] for k in range(n+2)]
a=[]
for j in range(n):
 t=sys.stdin.readline().strip()
 a.append(list(t))
q=int(input())
for j in range(0,q):
 x1,y1,x2,y2=map(int,sys.stdin.readline().split())
 dp[x1][y1]+=1
 dp[x2+1][y2+1]+=1
 dp[x1][y2+1]-=1
 dp[x2+1][y1]-=1
#print(dp)
for j in range(1,n+1):
 for k in range(1,m+1):
  dp[j][k]=dp[j][k]+dp[j-1][k]+dp[j][k-1]-dp[j-1][k-1]
  #print(dp[j][k],a[j-1][k-1])
  if dp[j][k]%2!=0:
   a[j-1][k-1]=int(a[j-1][k-1])^1
for j in range(n):
 print(''.join(map(str,a[j])))

import sys
n,m=map(int,input().split())
dp=[[0 for j in range(m+2)] for k in range(n+2)]
a=[]
for j in range(n):
 t=sys.stdin.readline().strip()
 a.append(list(t))
#print(a)
q=int(input())
for j in range(0,q):
 x1,y1,x2,y2=map(int,sys.stdin.readline().split())
 dp[x1][y1]+=1
 dp[x2+1][y2+1]+=1
 dp[x1][y2+1]-=1
 dp[x2+1][y1]-=1
#print(dp)
for j in range(1,n+1):
 for k in range(1,m+1):
  dp[j][k]=dp[j][k]+dp[j-1][k]+dp[j][k-1]-dp[j-1][k-1]
  #print(dp[j][k],a[j-1][k-1])
  if dp[j][k]%2!=0:
   a[j-1][k-1]=int(a[j-1][k-1])^1
for j in range(n):
 print(''.join(map(str,a[j])))