#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string p, h;
    cin >> p >> h;
    int len1 = p.length();
    int len2 = h.length();
    if (len1 > len2) {
      cout << "NO\n";
      continue;
    } else {
      bool flag = false;
      sort(p.begin(), p.end());
      for (int i = 0; i <= len2 - len1; i++) {
        string x = h.substr(i, len1);
        sort(x.begin(), x.end());
        if (x == p) {
          flag = true;
          cout << "YES\n";
          break;
        }
      }
      if (flag) {
      } else {
        cout << "NO\n";
      }
    }
  }
  return 0;
}
