#include <bits/stdc++.h>
using namespace std;
void get_next(string t, int next[])
{
int i = 1, j = 0;
next[1] = 0;
while (i < t.size() - 1)
{
if (j == 0 || t[i] == t[j])
{
i ++;
j ++;
if (t[i] != t[j]) next[i] = j;
else next[i] = next[j];
}
else j = next[j];
}
}
int index_kmp(string people, string temp, int pos, int next[])
{
int i = pos, j = 1;
while (i < people.size() && j < temp.size())
{
if (j == 0 || people[i] == temp[j])
{
i ++;
j ++;
}
else j = next[j];
}
if (j >= temp.size()) return i - temp.size() + 1;
else return 0;
}
bool virus_detection(string virus, string people)
{
string d_virus = virus;
for (int i = 1; i <= virus.size() - 1; ++i)
d_virus += virus[i];
int flag = 0;
for (int i = 1; i <= virus.size() - 1; ++i)
{
string temp = " ";
for (int j = i; j <= i + virus.size() - 2; ++j)
temp += d_virus[j];
int next[virus.size()];
get_next(temp, next);
flag = index_kmp(people, temp, 1, next);
if (flag) break;
}
if (flag) return true;
else return false;
}
int main()
{
int n;
cin >> n;
string virus, people;
while (n --)
{
cin >> virus + 1 >> people + 1;
if (virus_detection(virus, people)) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}