Hihocoder #1240 Image Encryption

Source: Internet
Author: User

Description

A Fancy square Image encryption algorithm works as follow:

0. Consider the image as an n x n matrix

1. Choose an integer k∈{0, 1, 2, 3}

2. Rotate the square image K * degree clockwise

3. If N is odd stop the encryption process

4. If N is even split the image to four equal sub-squares whose length is N/2 and encrypt them recursively starting FR Om Step 0

Apparently different choices of the K Serie result in different encrypted images. Given-Images A and B, your task is to find out whether it's POSSIBLE that's encrypted from A. B is possibly Encryp Ted from a if there are A choice of K serie that encrypt A into B.

Input

Input may contains multiple testcases.

The first line of the input contains a integer t (1 <= t <=) which is the number of testcases.

The first line of each testcase are an integer N, the length of the side of the images A and B.

The following n lines each contain n integers, indicating the image A.

The next following n lines each contain n integers, indicating the image B.

For 20% of the data, 1 <= n <= 15

For 100% of the data, 1 <= n <=, 0 <= Aij, Bij <= 100000000

Output

For the testcase output Yes or No according to whether it was possible that B was encrypted from A.

Sample Input
321 23 43 14 221 24 33 14 244 1 2 31 2 3 42 3 4 13 4 1 23 4 4 12 3 1 21 4 4 32 1 3 2
Sample Output
Yesnoyes

Hihocoder #1240 Image encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.