#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    int len1 = s1.length(), len2 = s2.length();
    int a[26] = {0}, mark = 0;
    multiset<char, greater<int> > st1, st2;
    for (int i = 0; i < len1; i++) {
      a[s1[i] - 97]++;
      st1.insert(s1[i]);
    }
    for (int i = 0; i < len2; i++) {
      if (a[s2[i] - 97] > 0) {
        int b[26] = {0};
        st2.clear();
        for (int j = i; j < len2; j++) {
          b[s2[j] - 97]++;
          if (b[s2[j] - 97] > a[s2[j] - 97]) {
            break;
          } else {
            st2.insert(s2[j]);
          }
        }
        if (st1 == st2) {
          mark = 1;
          break;
        }
      }
    }
    if (mark == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
