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.awt.PageAttributes;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class A {
	static int n;
	static int[] a;
	static int[] b;

	static int[][] memo;
	static HashMap<Integer, Integer> hm;

	static int dp(int idxA, int idxB) {
		if (idxA == n || idxB == n)
			return 0;
		if (memo[idxA][idxB] != -1)
			return memo[idxA][idxB];
		int l = dp(idxA + 1, idxB);
		int t = 0;
		int temp = hm.get(a[idxA]);
		if (temp >= idxB)
			t = 1 + dp(idxA + 1, temp + 1);
		return memo[idxA][idxB] = Math.max(l, t);
	}

	static int mod = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		int t = sc.nextInt();
		int[] dimarr = new int[1001];
		int d = 1;
		for (int i = 1; i < dimarr.length; i++) {
			d = (int) ((d * 1l * i) % mod);
			dimarr[i] = modinverse(d, mod);
		}

		while (t-- > 0) {
			int n = sc.nextInt();
			char[][] a = new char[n][n];
			for (int i = 0; i < a.length; i++) {
				a[i]=sc.next().toCharArray();
			}
			char[][] b = new char[n][n];
			for (int i = 0; i < a.length; i++) {
				b[i]=sc.next().toCharArray();
			}
			boolean[] col = new boolean[n];
			for (int i = 0; i < col.length; i++) {
				if (a[0][i] != b[0][i])
					col[i] = true;
			}
			boolean f = true;
			for (int i = 1; i < col.length; i++) {
				boolean g = true;
				for (int j = 0; j < col.length && g; j++) {
					if (col[j]) {
						g &= ('1' - a[i][j] + '0') == b[i][j];
					} else {
						g &= a[i][j] == b[i][j];
					}
				}
				if (g)
					continue;
				g = true;
				for (int j = 0; j < col.length && g; j++) {
					if (col[j]) {
						g &= a[i][j] == b[i][j];
					} else {
						g &= ('1' - a[i][j] + '0') == b[i][j];
					}
				}
				f &= g;
			}
			pw.println(f?"YES":"NO");
		}

		pw.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public int[] intArr(int n) throws IOException {
			int a[] = new int[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] longArr(int n) throws IOException {
			long a[] = new long[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

	static int modinverse(int n, int p) {
		return modPow(n, p - 2, p);
	}

	static int modPow(int a, int e, int mod) // O(log e)
	{
		a %= mod;
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res = (res * a) % mod;
			a = (int) ((a * 1l * a) % mod);
			e >>= 1;
		}
		return (int) res;
	}

	static int far[], value[];

	static final long INF = (long) 1e18; // don't increase, avoid overflow
	static ArrayList<Edge>[] adjList, g;
	static int V;

	/*
	 * 1. Dijkstra's Algorithm for SSSP on weighted graphs
	 */
	static long[][] dijkstra(int S, int T) // O(E log E)
	{
		long[][] dist = new long[4][V];
		for (int i = 0; i < dist.length; i++) {
			Arrays.fill(dist[i], INF);
		}

		PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
		dist[0][S] = 0;
		dist[1][S] = 0;
		dist[2][S] = 0;
		dist[3][S] = 0;
		pq.add(new Edge(S, 0)); // may add more in case of MSSP (Mult-Source)
		while (!pq.isEmpty()) {
//			System.out.println(pq);
			Edge cur = pq.remove();
			if (cur.free && cur.two) {
				if (cur.cost > dist[3][cur.node]) // lazy deletion
					continue;
			} else if (cur.free) {
				if (cur.cost > dist[1][cur.node]) // lazy deletion
					continue;
			} else if (cur.two) {
				if (cur.cost > dist[2][cur.node]) // lazy deletion
					continue;
			} else {
				if (cur.cost > dist[0][cur.node]) // lazy deletion
					continue;
			}
			for (Edge nxt : adjList[cur.node]) {
				if (cur.free && cur.two) {
					if (cur.cost + nxt.cost < dist[3][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[3][nxt.node] = cur.cost + nxt.cost, true, true));
				} else if (cur.free) {
					if (cur.cost + nxt.cost < dist[1][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[1][nxt.node] = cur.cost + nxt.cost, true, false));
					if (cur.cost + nxt.cost * 2 < dist[3][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[3][nxt.node] = cur.cost + nxt.cost * 2, true, true));
				} else if (cur.two) {
					if (cur.cost + nxt.cost < dist[2][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[2][nxt.node] = cur.cost + nxt.cost, false, true));
					if (cur.cost < dist[3][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[3][nxt.node] = cur.cost, true, true));
				} else {
					if (cur.cost + nxt.cost < dist[0][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[0][nxt.node] = cur.cost + nxt.cost, false, false));
					if (cur.cost < dist[1][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[1][nxt.node] = cur.cost, true, false));
					if (cur.cost + nxt.cost * 2 < dist[2][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[2][nxt.node] = cur.cost + nxt.cost * 2, false, true));
					if (cur.cost + nxt.cost < dist[3][nxt.node]) // lazy deletion
						pq.add(new Edge(nxt.node, dist[3][nxt.node] = cur.cost + nxt.cost, true, true));
				}
			}
		}
		return dist;

	}

	static class Edge implements Comparable<Edge> {
		int node;
		long cost;
		boolean free, two;

		Edge(int a, int b) {
			node = a;
			cost = b;
		}

		Edge(int a, long b, boolean f, boolean g) {
			node = a;
			cost = b;
			free = f;
			two = g;
		}

		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return node + " " + cost + " " + free + " " + two;
		}

		public int compareTo(Edge e) {
			return Long.compare(cost, e.cost);
		}
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;
		int idx;

		public pair(int d, int u, int i) {
			x = d;
			y = u;
			idx = i;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			if (o.x == x)
				return o.y - y;
			return o.x - x;
		}

		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return x + " " + y;
		}

	}
}