#include <bits/stdc++.h>
using namespace std;
char a[110], b[110], cmp[110];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s %s", a, b);
    int lena = strlen(a);
    int lenb = strlen(b);
    int flag = 0;
    if (lenb < lena)
      flag = 0;
    else if (lenb == lena) {
      sort(a, a + lena);
      sort(b, b + lenb);
      if (strcmp(a, b) == 0) flag = 1;
    } else if (lenb > lena) {
      sort(a, a + lena);
      for (int i = 0; i < lenb - lena + 1; i++) {
        int cnt = 0;
        int sum = 0;
        for (int j = i; j < i + lena; j++) {
          cmp[cnt++] = b[j];
        }
        sort(cmp, cmp + lena);
        for (int k = 0; k < lena; k++) {
          if (cmp[k] != a[k]) {
            sum = 1;
            break;
          }
        }
        if (sum == 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1)
      printf("YES\n");
    else if (flag == 0)
      printf("NO\n");
  }
  return 0;
}
