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.
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
#define mod1 1610612741
#define mul 31
#define PI 3.14159265358979323846264
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> ii;
//priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[200005],a(1000005),b(1000005,0),f(1000005),d(1000005,0);
//set<pair<lli,lli>>s;
//vector<vector<lli>>dp(5005,vector<lli>(5005,-1));
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
map<lli,lli>mp;
//vector<pair<pair<lli, lli>,lli> > st;
//map<lli,lli> np;
//queue<lli> qy;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
void fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
lli find(lli x)
{
    if(f[x]==x)
        return x;
    else
        return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
    return x<y;
}
lli comb(lli i,lli j)
{
    if(j>i)return 0;
    lli k=f[i];
    lli g=(f[j]*(f[i-j]))%mod;
    lli h=bpow(g,mod-2);
    return (k*h)%mod;
}
/*void sieve()
{
    for(lli i=2;i<=sqrt(10000000);i++)
    {
        if(b[i]==0)
        {
            k.pb(i);
        for(lli j=2;i*j<=sqrt(10000000);j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
vector<vector<lli>> x(1005,vector<lli>(1005,0)),y(1005,vector<lli>(1005,0)),z(1005,vector<lli>(1005,0));
lli n;
void allot(lli k)
{
    //cout<<k<<endl;
    for(lli i=1;i<=n;i++)
    {
        if(z[i][1]==k)b[i]=0;
        else b[i]=1;
        //cout<<i<<" "<<b[i]<<endl;
    }
}
bool check()
{
    lli f=0;
    for(lli i=1;i<=n;i++)
    {
        lli c1=0,c0=0;
        for(lli j=1;j<=n;j++)
        {
            if(z[j][i]!=b[j])
            {
                c1++;
            }
            else
            {
                c0++;
            }
        }
        //cout<<i<<" "<<c1<<" "<<c0<<endl;
        if(c1!=0 && c0!=0)f=1;
    }
    if(f)return false;
    else return true;
}
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli t;cin>>t;
    while(t--)
    {
        cin>>n;
        string s[n];
        for(lli i=0;i<n;i++)
        {
            cin>>s[i];
        }
        for(lli i=0;i<n;i++)
        {
            for(lli j=0;j<n;j++)
            {
                x[i+1][j+1]=s[i][j]-'0';
            }
        }
        for(lli i=0;i<n;i++)
        {
            cin>>s[i];
        }
        for(lli i=0;i<n;i++)
        {
            for(lli j=0;j<n;j++)
            {
                y[i+1][j+1]=s[i][j]-'0';
            }
        }
        for(lli i=1;i<=n;i++)
        {
            for(lli j=1;j<=n;j++)
            {
                if(x[i][j]==y[i][j])z[i][j]=0;
                else z[i][j]=1;
            }
        }
        allot(0);
        lli f=0;
        if(check())f=1;
        allot(1);
        if(check())f=1;
        if(f)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}

