#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1009;
void fastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fastIO();
  int t;
  cin >> t;
  string s1, s2, s;
  for (int i = 0; i < t; i++) {
    int ans = 0;
    cin >> s1 >> s2;
    sort(s1.begin(), s1.end());
    for (int i = 0; i < int(s2.size()) - int(s1.size()) + 1; i++) {
      s = s2.substr(i, s1.size());
      sort(s.begin(), s.end());
      ans = max(ans, int(s1 == s));
    }
    if (ans)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
