D. Y Flip
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two $$$n*m$$$ binary matrixs $$$a,b$$$ and an integer $$$l$$$.

Define a Y as an element set which contains $$$4$$$ elements.There are $$$4$$$ types of Y:

Type $$$1$$$:$$${a_{x,y},a_{x-1,y-1},a_{x-1,y+1},a_{x+1,y-1}}$$$

Type $$$2$$$:$$${a_{x,y},a_{x-1,y-1},a_{x-1,y+1},a_{x+1,y+1}}$$$

Type $$$3$$$:$$${a_{x,y},a_{x-1,y-1},a_{x+1,y-1},a_{x+1,y+1}}$$$

Type $$$4$$$:$$${a_{x,y},a_{x-1,y+1},a_{x+1,y-1},a_{x+1,y+1}}$$$

Note none of the elements can exceed the boundary.

You can do the following operation for $$$a$$$ any number of times:choose a Y in $$$a$$$,flip each number in it.

Flip means:if the number is $$$0$$$ change it to $$$1$$$,otherwise change it to $$$0$$$.

Find if $$$a$$$ can change to $$$b$$$ after any number of operations.

Input

The first line of input will contain a single integer $$$t(t \leq 300)$$$, denoting the number of test cases.

Each test case consists of multiple lines of input.

The first line of each test case contains two space-separated integers $$$n$$$,$$$m$$$$$$(3 \leq n,m \leq 1000)$$$.

The next $$$n$$$ lines describe $$$a$$$.There are $$$m$$$ numbers in each line. The $$$j^{th}$$$ number in line $$$i$$$ represents $$$a_{i,j}(0 \leq a_{i,j} \leq 1)$$$.

The next $$$n$$$ lines describe $$$b$$$.There are $$$m$$$ numbers in each line. The $$$j^{th}$$$ number in line $$$i$$$ represents $$$b_{i,j}(0 \leq b_{i,j} \leq 1)$$$.

The sum of $$$n,m$$$ over all test cases won't exceed $$$1000$$$.

Output

For each test case, output on a new line:if $$$a$$$ can change to $$$b$$$ after any number of operations,output $$$YES$$$,otherwise output $$$NO$$$.

Example
Input
5
3 3
1 0 1
0 1 0
0 0 0
1 0 1
0 1 0
1 0 1
3 3
0 0 0
0 0 0
0 0 0
0 1 0
1 0 1
0 1 0
4 4
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
4 4
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
0 0 0 0
0 0 0 0
1 1 1 0
1 1 1 0
3 4
0 1 0 0
0 1 1 1
1 0 0 1
0 1 0 1
0 1 0 1
0 0 1 1
Output
YES
NO
YES
NO
YES
Note

Test case $$$1$$$:

  1. flip $$${a_{2,2},a_{1,1},a_{1,3},a_{3,1}}$$$

  2. flip $$${a_{2,2},a_{1,1},a_{1,3},a_{3,3}}$$$

Test case $$$2$$$:It can be proved there's no way to change $$$a$$$ to $$$b$$$.