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.
// Grzegorz Suwaj
// TEMPLATE
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FE(i, a, b) for (size_t i = a; i < b; i++)
#define FI(i, a, b) for (size_t i = a; i <= b; i++)
#define RFE(i, a, b) for (int i = a; i > b; i--)
#define RFI(i, a, b) for (int i = a; i >= b; i--)
#define RANGE(c) (c).begin(), (c).end()
#define RRANGE(c) (c).rbegin(), (c).rend()
#define mp std::make_pair
#define fi first
#define se second
#define th third
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define bgn begin
#define ers erase
#define ins insert
#define putcxi putchar_unlocked
#define getcxi getchar_unlocked
#define y1 _y1
#define y0 _y0
#define esle else
#define szie size
#define siez size
#define szie_t size_t
#define isze size
#define boid void
#define itn int
#define breal break
#define bakc back

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = std::pair<int, int>;
using pill = std::pair<int, ll>;
using plli = std::pair<ll, int>;
using pll = std::pair<ll, ll>;
using pld = std::pair<ld, ld>;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using vld = std::vector<ld>;
using vpi = std::vector<pi>;
using vpill = std::vector<pill>;
using vplii = std::vector<plli>;
using vpll = std::vector<pll>;
using vpld = std::vector<pld>;
using vvi = std::vector<vi>;
using vvll = std::vector<vll>;
using vvvi = std::vector<vvi>;
using vvpi = std::vector<vpi>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;
using si = std::set<int>;
using sll = std::set<ll>;
using sull = std::set<ull>;
using spi = std::set<pi>;

const int MAX_INT = std::numeric_limits<int>::max();
const int MXI = 1e9;
const ll MAX_LL = std::numeric_limits<long long>::max();
const ull MAX_ULL = std::numeric_limits<unsigned long long>::max();
const ll MXLL = 1e18;

template <typename T1, typename T2, typename T3>
class triple {
public:
    T1 first;
    T2 second;
    T3 third;

    constexpr triple() {}
    constexpr triple(const T1& first, const T2& second, const T3& third)
        : first(first)
        , second(second)
        , third(third)
    {
    }
    triple(const triple& t) = default;
    triple(triple&& t) = default;

    triple& operator=(const triple& t)
    {
        first = t.first;
        second = t.second;
        third = t.third;
        return *this;
    }
    bool operator==(const triple& t) const
    {
        return first == t.first && second == t.second && third == t.third;
    }
    bool operator!=(const triple& t) const
    {
        return !(*this == t);
    }
    bool operator<(const triple& t) const
    {
        if (first == t.first) {
            if (second == t.second)
                return third < t.third;
            return second < t.second;
        }
        return first < t.first;
    }
    bool operator>(const triple& t) const
    {
        if (first == t.first) {
            if (second == t.second)
                return third > t.third;
            return second > t.second;
        }
        return first > t.first;
    }
    bool operator<=(const triple& t) const
    {
        return !(*this > t);
    }
    bool operator>=(const triple& t) const
    {
        return !(*this < t);
    }

    friend std::ostream& operator<<(std::ostream& os, const triple& t)
    {
        return os << t.fi << ' ' << t.se << ' ' << t.th;
    }
};

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
    return os << p.fi << ' ' << p.se;
}
template <typename... T, template <typename...> class Container, typename std::enable_if<!std::is_same<Container<T...>, std::string>::value>::type* = nullptr>
std::ostream& operator<<(std::ostream& os, const Container<T...>& c)
{
    for (auto&& x : c)
        os << x << ' ';
    // os << '\n';
    return os;
}
// KOD CODE PROGRAM SOURCE
int t;

boid ReverseRow(int row, vvb& vec)
{
    for (size_t i = 0; i < vec.size(); i++)
        vec[row][i] = !vec[row][i];
}
void ReverseCol(int col, vvb& vec)
{
    for (size_t i = 0; i < vec.size(); i++)
        vec[i][col] = !vec[i][col];
}

int main()
{
#ifndef DEBUG
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
#endif

    std::cin >> t;
    while (t--) {
        int n;
        std::cin >> n;
        vvb a(n, vb(n)), b(n, vb(n));
        for (size_t i = 0; i < n; i++)
            for (size_t j = 0; j < n; j++) {
                char c;
                std::cin >> c;
                if (c == '1')
                    a[i][j] = true;
            }
        for (size_t i = 0; i < n; i++)
            for (size_t j = 0; j < n; j++) {
                char c;
                std::cin >> c;
                if (c == '1')
                    b[i][j] = true;
            }

        for (size_t i = 0; i < n; i++)
            if (a[0][i] != b[0][i])
                ReverseCol(i, a);

        bool foundIssue = false;
        FE (i, 1, n)
            if (a[i] != b[i] && (ReverseRow(i, a), a[i] != b[i])) {
                foundIssue = true;
                break;
            }
        if (foundIssue)
            std::cout << "NO\n";
        else
            std::cout << "YES\n";
    }
    return 0;
}