#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,maxx,ans,tp,tp2,tp3;
string a,b;
cin>>t;
while(t--)
{
tp3=0;
ans=0;
maxx=0;
cin>>a>>b;
if(a.size()>b.size()) swap(a,b);
for(int i=0;i<a.size();i++)
for(int j=0;j<b.size();j++)
{
ans=0;
for(int k=0;i+k<a.size()&&j+k<b.size();k++)
{
if(a[i+k]==b[j+k]) ans++;
if(a[i+k]!=b[j+k])
{
if(ans>maxx)
{
maxx=ans;
tp=i;
tp2=j;
}
break;
}
}
if(ans>maxx)
{
maxx=ans;
tp=i;
tp2=j;
}
}
if(maxx==0)
{
cout<<"NO"<<endl;
continue;
}
if(tp>0||tp2>0) tp3++;
if(tp2+maxx<b.size()||tp+maxx<a.size()) tp3++;
if(tp3>maxx)
{
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
if(tp>0||tp2>0) cout<<'*';
for(int i=0;i<maxx;i++) cout<<a[i+tp];
if(tp2+maxx<b.size()||tp+maxx<a.size()) cout<<'*';
cout<<endl;
}
return 0;
}