#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
int num[30], a[30];
char s[N], t[N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%s%s", s + 1, t + 1);
    int n = strlen(s + 1), m = strlen(t + 1);
    if (m < n) {
      puts("NO");
      continue;
    }
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) a[s[i] - 'a']++;
    int iif = 0;
    for (int i = n; i <= m; i++) {
      memset(num, 0, sizeof(num));
      for (int j = i - n + 1; j <= i; j++) num[t[j] - 'a']++;
      int ok = 1;
      for (int j = 0; j < 26; j++)
        if (num[j] != a[j]) ok = 0;
      if (ok) {
        iif = 1;
        break;
      }
    }
    if (iif)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
