#include <bits/stdc++.h>
using namespace std;
void solve() {
  string a, b;
  cin >> a >> b;
  long long int of[26] = {0};
  long long int l = a.length();
  for (long long int i = 0; i < l; i++) {
    of[a[i] - 'a']++;
  }
  for (long long int i = 0; i < b.length() - l + 1; i++) {
    long long int freq[26] = {0};
    for (long long int j = i; j < i + l; j++) {
      freq[b[j] - 'a']++;
    }
    bool poss = true;
    for (long long int j = 0; j < 26; j++) {
      if (freq[j] != of[j]) poss = false;
    }
    if (poss) {
      cout << "YES\n";
      return;
    }
  }
  cout << "NO\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
