def szyfr(t, lancuchy):
wyniki = []
for i in range(t):
lancuch1 = lancuchy[2 * i]
lancuch2 = lancuchy[2 * i + 1]
if lancuch1 in (lancuch2 + lancuch2):
print("yes")
else:
print("no")
return wyniki
t = int(input())
lancuchy = []
for j in range(2 * t):
lancuchy.append(input().strip())
wyniki = szyfr(t, lancuchy)
print("\n".join(wyniki))
ZGVmIHN6eWZyKHQsIGxhbmN1Y2h5KToKICAgIHd5bmlraSA9IFtdCiAgICAKICAgIGZvciBpIGluIHJhbmdlKHQpOgogICAgICAgIGxhbmN1Y2gxID0gbGFuY3VjaHlbMiAqIGldCiAgICAgICAgbGFuY3VjaDIgPSBsYW5jdWNoeVsyICogaSArIDFdCiAgICAgICAgCiAgICAgICAgaWYgbGFuY3VjaDEgaW4gKGxhbmN1Y2gyICsgbGFuY3VjaDIpOgogICAgICAgICAgICBwcmludCgieWVzIikKICAgICAgICBlbHNlOgogICAgICAgICAgICBwcmludCgibm8iKQogICAgCiAgICByZXR1cm4gd3luaWtpCnQgPSBpbnQoaW5wdXQoKSkKbGFuY3VjaHkgPSBbXQpmb3IgaiBpbiByYW5nZSgyICogdCk6CiAgICBsYW5jdWNoeS5hcHBlbmQoaW5wdXQoKS5zdHJpcCgpKQp3eW5pa2kgPSBzenlmcih0LCBsYW5jdWNoeSkKICAgIAoKcHJpbnQoIlxuIi5qb2luKHd5bmlraSkpCg==