#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s1, s2;
    int fflag = 0;
    cin >> s1;
    cin >> s2;
    int l1 = s1.size();
    int l2 = s2.size();
    int a[26] = {0};
    for (int i = 0; i < l1; i++) {
      a[s1[i] - 'a']++;
    }
    if (l1 > l2) {
      cout << "NO" << endl;
      continue;
    }
    for (int i = 0; i <= l2 - l1; i++) {
      int b[26] = {0};
      for (int j = 0; j < l1; j++) {
        b[s2[i + j] - 'a']++;
      }
      int flag = 1;
      for (int j = 0; j < 26; j++) {
        if (a[j] != b[j]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        cout << "YES" << endl;
        fflag = 1;
        break;
      }
    }
    if (!fflag) cout << "NO" << endl;
  }
  return 0;
}
