#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  int t;
  cin >> t;
  string p, h;
  while (t--) {
    cin >> p >> h;
    int n = p.size();
    int cnt[26];
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; i++) cnt[p[i] - 'a']++;
    int m = h.size();
    bool ok = 0;
    for (int i = 0; !ok && i <= m - n; i++) {
      int c2[26];
      memset(c2, 0, sizeof c2);
      for (int j = 0; j < n; j++) {
        c2[h[i + j] - 'a']++;
      }
      ok = 1;
      for (int j = 0; ok && j < 26; j++)
        if (cnt[j] != c2[j]) ok = 0;
    }
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
}
