#include <bits/stdc++.h>
using namespace std;
int m, n;
char s1[222], s2[222], st[222];
int main() {
  int i, j, test, cas = 0, f, l1, l2;
  int a, b;
  scanf("%d", &test);
  while (test--) {
    scanf("%s %s", s1, s2);
    l1 = strlen(s1);
    l2 = strlen(s2);
    f = 0;
    sort(s1, s1 + l1);
    for (i = 0; i + l1 <= l2; i++) {
      strcpy(st, s2 + i);
      st[l1] = 0;
      sort(st, st + l1);
      if (strcmp(st, s1) == 0) {
        f = 1;
        break;
      }
    }
    if (f)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
