#C8940. Matrix Transformation Check

    ID: 52978 Type: Default 1000ms 256MiB

Matrix Transformation Check

Matrix Transformation Check

You are given two matrices (A) and (B) each of size (N\times M). In one operation, you can add 1 to every element in any chosen submatrix of (A). Your task is to determine whether it is possible to transform (A) into (B) using a sequence of these operations. It can be shown that the transformation is possible if and only if the difference (B_{ij} - A_{ij}) is the same for every element ((i, j)) in the matrices. Output “Yes” if the transformation is possible, otherwise output “No”.

inputFormat

The input begins with an integer (T) representing the number of test cases. Each test case contains the following:\

  • The first line has two integers, (N) and (M), the number of rows and columns.\
  • The next (N) lines each contain (M) integers representing matrix (A).\
  • The following (N) lines each contain (M) integers representing matrix (B).

outputFormat

For each test case, print a single line containing (Yes) if matrix (A) can be transformed into matrix (B) by the defined operation, or (No) otherwise.## sample

2
2 2
1 2
2 3
2 3
3 4
2 2
1 2
2 3
2 4
3 5
Yes

No

</p>