#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k, i, j;
  bool flag, flag1, final_flag;
  string p, q;
  cin >> t;
  for (i = 0; i < t; i++) {
    map<char, int> m;
    final_flag = false;
    cin >> p >> q;
    for (j = 0; j < p.size(); j++) {
      if (m.find(p[j]) == m.end())
        m[p[j]] = 1;
      else
        m[p[j]] += 1;
    }
    for (j = 0; j < q.size(); j++) {
      map<char, int> m1;
      flag1 = true;
      flag = true;
      if (m.find(q[j]) != m.end()) {
        k = j;
        for (k = j; k < p.size() + j; k++) {
          if (m.find(q[k]) == m.end()) {
            flag = false;
            break;
          } else {
            if (m1.find(q[k]) == m1.end())
              m1[q[k]] = 1;
            else
              m1[q[k]] += 1;
          }
        }
        if (flag) {
          map<char, int>::iterator it;
          for (it = m.begin(); it != m.end(); it++) {
            if (m1.find(it->first) == m1.end()) {
              flag1 = false;
              break;
            }
            if (m1[it->first] != m[it->first]) {
              flag1 = false;
              break;
            }
          }
          if (flag1) final_flag = true;
        }
      }
      if (final_flag) break;
    }
    if (final_flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
