You are given two binary square matrices a and b of size n × n. A matrix is called binary if each of its elements is equal to 0 or 1. You can do the following operations on the matrix a arbitrary number of times (0 or more): 

  * vertical xor. You choose the number j (1 ≤ j ≤ n) and for all i (1 ≤ i ≤ n) do the following: a_{i, j} := a_{i, j} ⊕ 1 (⊕ — is the operation [xor](https://en.wikipedia.org/wiki/Exclusive_or) (exclusive or)). 
  * horizontal xor. You choose the number i (1 ≤ i ≤ n) and for all j (1 ≤ j ≤ n) do the following: a_{i, j} := a_{i, j} ⊕ 1. 



Note that the elements of the a matrix change after each operation.

For example, if n=3 and the matrix a is: $$$ \begin{pmatrix} 1 & 1 & 0 \\\ 0 & 0 & 1 \\\ 1 & 1 & 0 \end{pmatrix} $$$ Then the following sequence of operations shows an example of transformations: 

  * vertical xor, j=1. $$$ a= \begin{pmatrix} 0 & 1 & 0 \\\ 1 & 0 & 1 \\\ 0 & 1 & 0 \end{pmatrix} $$$ 
  * horizontal xor, i=2. $$$ a= \begin{pmatrix} 0 & 1 & 0 \\\ 0 & 1 & 0 \\\ 0 & 1 & 0 \end{pmatrix} $$$ 
  * vertical xor, j=2. $$$ a= \begin{pmatrix} 0 & 0 & 0 \\\ 0 & 0 & 0 \\\ 0 & 0 & 0 \end{pmatrix} $$$ 



Check if there is a sequence of operations such that the matrix a becomes equal to the matrix b.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.

The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the size of the matrices.

The following n lines contain strings of length n, consisting of the characters '0' and '1' — the description of the matrix a.

An empty line follows.

The following n lines contain strings of length n, consisting of the characters '0' and '1' — the description of the matrix b.

It is guaranteed that the sum of n over all test cases does not exceed 1000.

Output

For each test case, output on a separate line: 

  * "YES", there is such a sequence of operations that the matrix a becomes equal to the matrix b; 
  * "NO" otherwise. 



You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

Example

Input


3
3
110
001
110

000
000
000
3
101
010
101

010
101
010
2
01
11

10
10


Output


YES
YES
NO

Note

The first test case is explained in the statements.

In the second test case, the following sequence of operations is suitable: 

  * horizontal xor, i=1; 
  * horizontal xor, i=2; 
  * horizontal xor, i=3; 



It can be proved that there is no sequence of operations in the third test case so that the matrix a becomes equal to the matrix b.
import java.util.*;
import java.io.*;

public class Solution{
    public static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (st == null || !st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) {
                a[i]=nextInt();
            }
            return a;
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    public static class unionFind{
        public static int[] p;
        public static int find(int u){
            while(p[u]!=u){
                u=p[u];
            }
            return u;
        }
        public static void union(int u,int v){
            int x=find(u);
            int y=find(v);
            p[x]=y;
        }
    }
    static class Point{
        double x;
        double y;
        public Point(double x, double y){
            this.x = x;
            this.y = y;
        }
    }
    public static class SegmentTree{
        int st1[];
        int st2[];
        SegmentTree(int arr[], int n){
            int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
            int max_size = 2 * (int) Math.pow(2, x) - 1;
            st1 = new int[max_size];
            st2 = new int[max_size];
            constructSTUtil1(arr, 0, n - 1, 0);
            constructSTUtil2(arr, 0, n - 1, 0);
        }
        int getMid(int s, int e) {
            return s + (e - s) / 2;
        }
        int getSumUtil(int ss, int se, int qs, int qe, int si){
            if (qs <= ss && qe >= se){
                return st1[si];
            }
            if (se < qs || ss > qe) {
                return 0;
            }
            int mid = getMid(ss, se);
            return getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
        }
        int getMinUtil(int ss, int se, int qs, int qe, int si){
            if (qs <= ss && qe >= se){
                return st2[si];
            }
            if (se < qs || ss > qe) {
                return Integer.MAX_VALUE;
            }
            int mid = getMid(ss, se);
            return Math.min(getMinUtil(ss, mid, qs, qe, 2 * si + 1),getMinUtil(mid + 1, se, qs, qe, 2 * si + 2));
        }
        int getMaxUtil(int ss, int se, int qs, int qe, int si){
            if (qs <= ss && qe >= se){
                return st1[si];
            }
            if (se < qs || ss > qe) {
                return Integer.MIN_VALUE;
            }
            int mid = getMid(ss, se);
            return Math.max(getMaxUtil(ss, mid, qs, qe, 2 * si + 1),getMaxUtil(mid + 1, se, qs, qe, 2 * si + 2));
        }
        void updateValueUtil(int ss, int se, int i, int diff, int si){
            if (i < ss || i > se){
                return;
            }
            st1[si] = st1[si] + diff;
            if (se != ss) {
                int mid = getMid(ss, se);
                updateValueUtil(ss, mid, i, diff, 2 * si + 1);
                updateValueUtil(mid + 1, se, i, diff, 2 * si + 2);
            }
        }
        void updateValue(int arr[], int n, int i, int new_val){
            if (i < 0 || i > n - 1) {
                return;
            }
            int diff = new_val - arr[i];
            arr[i] = new_val;
            updateValueUtil(0, n - 1, i, diff, 0);
        }
        int getSum(int n, int qs, int qe){
            if (qs < 0 || qe > n - 1 || qs > qe) {
                return -1;
            }
            return getSumUtil(0, n - 1, qs, qe, 0);
        }
        int getMin(int n, int qs, int qe){
            if (qs < 0 || qe > n - 1 || qs > qe) {
                return Integer.MIN_VALUE;
            }
            return getMinUtil(0, n - 1, qs, qe, 0);
        }
        int getMax(int n, int qs, int qe){
            if (qs < 0 || qe > n - 1 || qs > qe) {
                return Integer.MAX_VALUE;
            }
            return getMaxUtil(0, n - 1, qs, qe, 0);
        }
        int constructSTUtil1(int arr[], int ss, int se, int si){
            if (ss == se) {
                st1[si] = arr[ss];
                return arr[ss];
            }
            int mid = getMid(ss, se);
            st1[si] = Math.max(constructSTUtil1(arr, ss, mid, si * 2 + 1),constructSTUtil1(arr, mid + 1, se, si * 2 + 2));
            return st1[si];
        }
        int constructSTUtil2(int arr[], int ss, int se, int si){
            if (ss == se) {
                st2[si] = arr[ss];
                return arr[ss];
            }
            int mid = getMid(ss, se);
            st2[si] = Math.min(constructSTUtil2(arr, ss, mid, si * 2 + 1),constructSTUtil2(arr, mid + 1, se, si * 2 + 2));
            return st2[si];
        }
    }
    public static double area(Point A, Point B, Point C){
        double area = (A.x * (B.y - C.y) + B.x * (C.y - A.y) + C.x * (A.y - B.y)) / (double)2;
        return Math.abs(area);
    }
    public static void sort(int[] array){
        ArrayList<Integer> copy = new ArrayList<>();
        for(int i:array){
            copy.add(i);
        }
        Collections.sort(copy);
        for(int i=0;i<array.length;i++){
            array[i]=copy.get(i);
        }
    }
    static long[] fact(){
        long[] fac = new long[200001];
        fac[0] = (long)1;
        for (int i = 1; i < (int)fac.length; i++){
            fac[i] = (fac[i - 1] * i) % 1000000007;
        }
        return fac;
    }
    public static long nCr(long n, long r,long p,long[] fac){
        if (n<r)
            return (long)0;
        if (r == 0)
            return (long)1;
        return (fac[(int)n] * modInverse(fac[(int)r], p)% p * modInverse(fac[(int)(n - r)], p)% p)% p;
    }
    public static long modInverse(long n, long p){
        return power(n, p - 2, p);
    }
    static long power(long x, long y, long p){
        long res = 1;
        x = x % p;
        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }
        return res;
    }
    public static int upp(int[] arr,int v){
        int low=0;
        int high=arr.length-1;
        int ans=-1;
        while(low<=high){
            int m=(low+high)/2;
            if(arr[m]<v){
                ans=m;
                low=m+1;
            }else{
                high=m-1;
            }
        }
        return ans;
    }
    public static int low(int[] arr,int v){
        int low=0;
        int high=arr.length-1;
        int ans=-1;
        while(low<=high){
            int m=(low+high)/2;
            if(arr[m]>=v){
                ans=m;
                high=m-1;
            }else{
                low=m+1;
            }
        }
        return ans;
    }
    public static int lowpair(long[] arr,long v){
        int low=0;
        int high=arr.length-1;
        int ans=-1;
        while(low<=high){
            int m=(low+high)/2;
            if(arr[m]>=v){
                ans=m;
                high=m-1;
            }else{
                low=m+1;
            }
        }
        return ans;
    }
    public static class Comp implements Comparator<pair>{
        public int compare(pair a,pair b){
            return b.x-a.x;
        }
    }
    public static int gcd(int a,int b){
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public static int lcm(int a,int b){
        int x=Math.max(a,b);
        int y=Math.min(a,b);
        long ans=x;
        while(ans%y!=0){
            ans+=x;
        }
        if(ans>Integer.MAX_VALUE){
            return -1;
        }
        return (int)ans;
    }
    public static class pair{
        int x;
        int y;
        public pair(int a,int b){
            x=a;
            y=b;
        }
    }
    static boolean isPowerOfTwo(long n)
    {
        if(n==0)
            return false;

        return (long)(Math.ceil((Math.log(n) / Math.log(2)))) ==
                (long)(Math.floor(((Math.log(n) / Math.log(2)))));
    }
    public static int ans;
    public static void main(String[] args) throws IOException{
        FastScanner fs=new FastScanner();
        int t=1;
        t=fs.nextInt();
        long mod=1000000007;
        long[] fact=fact();
        PrintWriter out=new PrintWriter(System.out);
        while(t-->0){
            int n=fs.nextInt();
            int[][] a=new int[n][n];
            int[][] b=new int[n][n];
            for(int i=0;i<n;i++){
                String s= fs.next();
                for(int j=0;j<n;j++){
                    a[i][j]=s.charAt(j)-'0';
                }
            }
//            String z= fs.next();
            for(int i=0;i<n;i++){
                String s= fs.next();
                for(int j=0;j<n;j++){
                    b[i][j]=s.charAt(j)-'0';
                }
            }
            int c=0;
            loop1:for(int j=0;j<n-1;j++){
                int z=0;
                //z=1 -> same;
                //z=2 -> reverse;
                for(int i=0;i<n;i++){
                    if(a[i][j] == b[i][j]){
                        if(a[i][j+1] == b[i][j+1]){
                            if(z==1){
                                continue;
                            }else if(z==0){
                                z=1;
                                continue;
                            }else{
                                c=1;
                                break loop1;
                            }
                        }else{
                            if(z==2){
                                continue;
                            }else if(z==0){
                                z=2;
                            }else{
                                c=1;
                                break loop1;
                            }
                        }
                    }else{
                        if(a[i][j+1] != b[i][j+1]){
                            if(z==1){
                                continue;
                            }else if(z==0){
                                z=1;
                                continue;
                            }else{
                                c=1;
                                break loop1;
                            }
                        }else{
                            if(z==2){
                                continue;
                            }else if(z==0){
                                z=2;
                            }else{
                                c=1;
                                break loop1;
                            }
                        }
                    }
                }
            }
            if(c==0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
        out.close();
    }
}