#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define MM(a) memset(a,0,sizeof(a))
const int N=100010;
char a[N],b[N],aa[2*N],bb[2*N];
int nexta[N],nextb[N];
inline void getnext(int ne[],char s[])
{
int j=0,k=ne[0]=-1;
int len=strlen(s);
while (j<len)
{
if(k==-1||s[j]==s[k])
{
j++;
k++;
ne[j]=k;
}
else
k=ne[k];
}
}
inline bool kmp(int ne[],char s[],char p[])
{
int i=0,j=0;
int la=strlen(s),lb=strlen(p);
while (i<la&&j<lb)
{
if(s[i]==p[j]||j==-1)
{
i++;
j++;
}
else
j=ne[j];
}
if(j==lb)
return true;
else
return false;
}
int main(void)
{
int tcase,i,j;
scanf("%d",&tcase);
while (tcase--)
{
MM(a);
MM(b);
MM(aa);
MM(bb);
MM(nexta);
MM(nextb);
scanf("%s%s",a,b);
if(strlen(a)!=strlen(b))
{
puts("No");
continue;
}
strcat(aa,a);
strcat(aa,a);
strcat(bb,b);
strcat(bb,b);
getnext(nexta,a);
getnext(nextb,b);
if(kmp(nexta,bb,a)||kmp(nextb,aa,b))
puts("Yes");
else
puts("No");
}
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
inline string minP(string s)
{
int i=0,j=1,k=0,l=s.size();
while (1)
{
if(i+k>=l||j+k>=l)
break;
if(s[i+k]==s[j+k])
{
k++;
continue;
}
else
{
if(s[j+k]>s[i+k])
j+=k+1;
else
i+=k+1;
k=0;
if(i==j)
j++;
}
}
s=s+s;
return s.substr(min(i,j),l);
}
int main(void)
{
ios::sync_with_stdio(false);
int tcase;
string a,b;
cin>>tcase;
while (tcase--)
{
cin>>a>>b;
a=minP(a);
b=minP(b);
if(a==b)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}