#include <bits/stdc++.h>
int main() {
  int32_t number_of_tests;
  std::cin >> number_of_tests;
  for (int32_t test = 0; test < number_of_tests; test++) {
    std::string s1, s2;
    std::cin >> s1 >> s2;
    if (s2.size() < s1.size()) {
      std::cout << "NO"
                << "\n";
      continue;
    }
    std::multiset<char> chars_password;
    for (int32_t i = 0; i < s1.size(); i++) chars_password.insert(s1[i]);
    bool answer = false;
    for (int32_t i = 0; i < s2.size() - s1.size() + 1; i++) {
      std::multiset<char> chracters;
      for (int32_t j = i; j < i + s1.size(); j++) chracters.insert(s2[j]);
      if (chars_password == chracters) answer = true;
    }
    std::cout << (answer ? "YES" : "NO") << "\n";
  }
  return 0;
}
