#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<string>
#include<math.h>
using namespace std ;
typedef long long ll;
#define MAXN 1005
#define INF 0x3f3f3f3f
typedef struct Chunk
{
char goal[MAXN]; //存放单链DNA
char type[MAXN*2]; //存放病毒
char mo[MAXN]; //模式串存放更新
int next[MAXN]; //KMP中模式串的next[j];
int leg; //单链DNA的长度;
int let; //病毒基因的长度
int flag; //判断是否匹配成功
} SString;
int KMP(SString &T) //KMP算法
{
int i=0, j=0;
while(i<T.leg && j<T.let)
{
if(j == -1 || T.goal[i] == T.mo[j])
{
++i;
++j;
}
else
j = T.next[j];
}
if(j > T.let-1)
return i-T.let;
else
return -1;
}
void NNext(SString &T) //next[j];
{
memset(T.next, 0, sizeof(T.next));
int i=0, j=-1;
T.next[0] = -1;
while(i<T.let)
{
if(j == -1 || T.mo[i] == T.mo[j])
{
if(T.mo[++i] == T.mo[++j])
T.next[i] = T.next[j];
else
T.next[i] = j;
}
else
j = T.next[j];
}
}
void init(SString &T) //输入
{
T.flag = -1;
scanf("%s%s", T.type, T.goal);
T.leg = strlen(T.goal);
T.let = strlen(T.type);
int i, j;
for(i=T.let, j=0; j<T.let; ++j)
T.type[i++] = T.type[j];
}
void print(SString T) //输出
{
for(int i=0; i<T.let; ++i)
cout << T.type[i];
cout << ' ' << T.goal << ' ';
if(T.flag != -1)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
int main()
{
int n;
cin >> n;
SString ss[n];
for(int i=0; i<n; ++i)
init(ss[i]);
for(int i=0; i<n; ++i)
{
for(int j=0; j<ss[i].let; ++j)
{
for(int k=0; k<ss[i].let; ++k) //模式串更新
ss[i].mo[k] = ss[i].type[k+j];
ss[i].mo[ss[i].let] = '\0'; //防止访问越界
NNext(ss[i]); //更新next[j];
ss[i].flag = KMP(ss[i]); //KMP查询
if(ss[i].flag != -1)
break;
}
}
cout<<"The result are as follows:"<<endl;
for(int i=0; i<n; ++i)
print(ss[i]);
return 0;
}