# Digit Operation Solution

## Problem

You are given arrays $�$ and $�$, each consisting of $�$ strings, and a positive integer $�$.
For all $1\le �\le �$, both ${�}_{�}$ and ${�}_{�}$ consist of characters from $0$ to $9$ (both inclusive).

You can perform the following types of operations on array $�$:

• Type $1$: Choose two indices $�$ and $�$ $\left(�\mathrm{\ne }�\right)$ and swap any character of ${�}_{�}$ with any character of ${�}_{�}$. The cost of this operation is $0$.
• Type $2$: Choose an index $�$ and replace one character of ${�}_{�}$ with any character from $0$ to $9$ (both inclusive). The cost of this operation is $1$.

For example, let $�=\left[24,30,51\right]$. A valid sequence of operations can be:

• Swap $4$ in ${�}_{1}=24$ with $0$ in ${�}_{2}=30$ to obtain $\left[20,34,51\right]$.
• Swap $0$ in ${�}_{1}=20$ with $5$ in ${�}_{3}=51$ to obtain $\left[25,34,01\right]$.
• Replace $0$ in ${�}_{3}=01$ with $1$ to obtain $\left[25,34,11\right]$.
The cost of the above sequence of operations is $1$.

Find whether we can convert the array $�$ to array $�$ using any (possibly zero) number of operations with cost $\le �$.

### Input Format

• The first line of input will contain a single integer $�$, denoting the number of test cases.
• Each test case consists of multiple lines of input.
• The first line of each test case contains two space-separated integers $�$ and $�$, the size of array and the maximum cost of operations.
• The second line of each test case contains $�$ space-separated strings ${�}_{1},{�}_{2},\dots ,{�}_{�}$.
• The third line of each test case contains $�$ space-separated strings ${�}_{1},{�}_{2},\dots ,{�}_{�}$.

### Output Format

For each test case, print YES if it is possible to convert array $�$ to $�$ using any (possibly zero) number of operations with cost $\le �$. Else, print NO.

You may print each character of the string in uppercase or lowercase (for example, the strings yEsyesYes, and YES will all be treated as identical).

### Constraints

• $1\le �\le 1000$
• $2\le �\le 1{0}^{5}$
• $1\le �\le 1{0}^{18}$
• $1\le \mathrm{\mid }{�}_{�}\mathrm{\mid },\mathrm{\mid }{�}_{�}\mathrm{\mid }\le 19$
• ${�}_{�}$ and ${�}_{�}$ consist of characters from $0$ to $9$ (both inclusive).
• The sum of $�$ over all test cases won't exceed $1{0}^{5}$.

### Sample 1:

Input
Output
3
2 2
1 9
9 1
2 2
1 11
11 1
4 1
22 13 12 89
28 98 21 31
YES
NO
YES


### Explanation:

Test case $1$: We can use one operation of type $1$ to swap $1$ in ${�}_{1}$ with $9$ in ${�}_{2}$. Thus, $�$ becomes $\left[9,1\right]$, which is equal to $�$. We are able to do this with $0$ cost, which is $\le 2$.

Test case $2$: It is impossible to convert $�$ to $�$ with at most $2$ cost.

#include <bits/stdc++.h>

using namespace std;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
#define scanit(a,n) for(ll indexaa=0; indexaa<n; indexaa++) cin>>a[indexaa];

inline int power(int a, int b)
{
int x = 1;
while (b)
{
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr (names + 1, ',');
cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;

void solve() {

int n,k;
cin>>n>>k;

vector<string>v(n),b(n);

for (int i = 0; i < n; i++)
{
cin>>v[i];
}

for (int i = 0; i < n; i++)
{
cin>>b[i];
}

map<char,map<char,int>>m;

for (int i = 0; i < n; i++)
{
if(v[i].length()!=b[i].length()){
cout<<"NO\n";
return;
}
for (int j = 0; j < v[i].size(); j++)
{
if(v[i][j]!=b[i][j])m[v[i][j]][b[i][j]]++;
}
}

for (int i = 0; i < n; i++)
{
for (int j = 0; j < v[i].size(); j++)
{
if(v[i][j]!=b[i][j]){
if(m[b[i][j]][v[i][j]]>0){
m[b[i][j]][v[i][j]]--;
}
else k--;
}
}

}

if(k<0)cout<<"NO\n";
else cout<<"YES\n";

}

int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

clock_t z = clock();

int t = 1;
cin >> t;
while (t--) solve();

return 0;
}