Assume we need to look for the following 2D pattern:
If we scan through the original array, we observe that the 2D pattern begins at the second row and the third column of the larger grid (the in the second row and third column of the larger grid is the top-left corner of the pattern we are searching for).
So, a 2D pattern of digits is said to be present in a larger grid , if the latter contains a contiguous, rectangular 2D grid of digits matching with the pattern , similar to the example shown above.
The first line contains an integer, , which is the number of test cases. test cases follow, each having a structure as described below:
The first line contains two space-separated integers, and , indicating the number of rows and columns in the grid , respectively.
This is followed by lines, each with a string of digits, which represent the grid .
The following line contains two space-separated integers, and , indicating the number of rows and columns in the pattern grid .
This is followed by lines, each with a string of digits, which represent the pattern .
Display 'YES' or 'NO', depending on whether (or not) you find that the larger grid contains the rectangular pattern .
The evaluation will be case sensitive.