#include <bits/stdc++.h>
using namespace std;
bool check(string& pass, string& hash, int begin,
           unordered_map<char, int> pass_map) {
  int i, j, n = pass.size(), m = hash.size();
  unordered_map<char, int> hash_map;
  for (i = begin; i <= begin + n - 1; i++) {
    hash_map[hash[i]]++;
  }
  for (auto it = pass_map.begin(); it != pass_map.end(); it++) {
    char temp1 = it->first;
    int temp2 = it->second;
    if (hash_map.find(temp1) != hash_map.end() && hash_map[temp1] == temp2) {
      continue;
    }
    return false;
  }
  return true;
}
void solve() {
  string pass, hash;
  cin >> pass >> hash;
  int n = pass.size(), m = hash.size(), i;
  if (m < n) {
    cout << "NO\n";
    return;
  }
  unordered_map<char, int> pass_map;
  for (i = 0; i < n; i++) {
    pass_map[pass[i]]++;
  }
  for (i = 0; i + n - 1 < m; i++) {
    if (check(pass, hash, i, pass_map)) {
      cout << "YES\n";
      return;
    }
  }
  cout << "NO\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
