#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int f = 0, c, p;
    string s, s1;
    cin >> s >> s1;
    int l = s.size();
    sort(s.begin(), s.end());
    for (int i = 0; i < s1.size(); i++) {
      if (l + i > s1.size()) {
        break;
      }
      string s3;
      int c = 0;
      for (int j = i; j < l + i; j++) {
        s3 += s1[j];
      }
      sort(s3.begin(), s3.end());
      for (int k = 0; k < s3.size(); k++) {
        if (s[k] == s3[k]) {
          c++;
        }
      }
      if (c == l) {
        p = 1;
      }
    }
    if (p == 1) {
      cout << "YES" << endl;
      p = 0;
    } else {
      cout << "NO" << endl;
      p = 0;
    }
  }
  return 0;
}
