#include <bits/stdc++.h>
const int INF = 0x7fffffff;
const long long int LNF = 0x7fffffffffffffff;
using namespace std;
int ac[26], az[26];
char aa[105], bb[105];
int main() {
  int i, k, nn, kk = 0, len1, len2, s;
  scanf("%d", &nn);
  getchar();
  while (kk < nn) {
    gets(aa);
    gets(bb);
    len1 = strlen(aa);
    len2 = strlen(bb);
    memset(az, 0, sizeof(az));
    k = 0;
    while (k < len1) {
      az[aa[k] - 'a']++;
      k++;
    }
    k = 0;
    s = 1;
    while (k + len1 <= len2) {
      memset(ac, 0, sizeof(ac));
      i = 0;
      while (i < len1) {
        ac[bb[k + i] - 'a']++;
        i++;
      }
      i = 0;
      s = 0;
      while (i < 26) {
        if (ac[i] != az[i]) {
          s = 1;
          break;
        }
        i++;
      }
      if (s == 0) {
        break;
      }
      k++;
    }
    if (s == 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    kk++;
  }
  return 0;
}
