#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    long long k;
    long long n1 = s1.length();
    long long n2 = s2.length();
    long long flag = 0;
    sort(s1.begin(), s1.end());
    for (long long i = 0; i < n2 - n1 + 1; i++) {
      string p = "";
      for (long long j = i; j < i + s1.length(); j++) p += s2[j];
      sort(p.begin(), p.end());
      for (k = 0; k < n1; k++) {
        if (p[k] != s1[k]) {
          break;
        }
      }
      if (k == n1) {
        cout << "YES" << endl;
        flag = 1;
        break;
      }
    }
    if (flag == 0) cout << "NO" << endl;
  }
}
