#include <bits/stdc++.h>
using namespace std;
int check(string s1, string s2) {
  int n = s1.size();
  int n1 = s2.size();
  sort(s1.begin(), s1.end());
  for (int i = 0; i <= n1 - n; i++) {
    string t = s2.substr(i, n);
    sort(t.begin(), t.end());
    if (s1 == t) {
      return 1;
    }
  }
  return 0;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1;
    string s2;
    cin >> s1 >> s2;
    if (check(s1, s2)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
