#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define lli long long int
#define endl "\n"
using namespace std;
void solve(){
int n, m;
cin >> n >> m;
//vector<char> a(),b();
char a[n],b[m];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
for (int i = 0; i < n; ++i)
{
cin>>b[i];
}
string s = "0123456789";
int x=max(n,m);
//cout<<x<<endl;
int count = 0;
for(int i = 0; i < 10;i++){
for(int j =0;j<x;j++){
if(s[i]==a[j]||s[i]==b[j]){
count++;
break;
}
}
//cout << s[i]<<endl;
}
//cout <<count<<endl;
if(count>=10)
cout << "YES"<<endl;
else
cout<<"NO"<<endl;
}
signed main() {
fast();
int t;
cin >> t;
while (t--)
solve();
return 0;
}