#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    int n1, n2, i, j, flag = 0;
    n1 = s1.size();
    n2 = s2.size();
    int hash1[26], hash2[26];
    for (i = 0; i < 26; i++) {
      hash1[i] = 0;
      hash2[i] = 0;
    }
    for (i = 0; i < n1; i++) {
      hash1[s1[i] - 97]++;
    }
    for (i = 0; i < n2; i++) {
      int k = i;
      flag = 0;
      int c = 0;
      for (j = 0; j < n1 && k < n2; j++) {
        c++;
        hash2[s2[k] - 97]++;
        k++;
      }
      if (c == n1) {
        for (int l = 0; l < 26; l++) {
          if (hash1[l] != hash2[l]) {
            flag = 1;
            break;
          }
        }
      } else {
        flag = 1;
      }
      if (flag == 0) {
        break;
      } else {
        for (int l = 0; l < 26; l++) {
          hash2[l] = 0;
        }
      }
    }
    if (flag == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
