#include <bits/stdc++.h>
using namespace std;
void solve(void) {
  long long Q;
  cin >> Q;
  for (long long que = 0; que < Q; que++) {
    string A, B;
    cin >> A >> B;
    long long check = 0;
    for (long long i = 0; i < (long long)B.size() - (long long)A.size() + 1;
         i++) {
      string sub = B.substr(i, A.size());
      sort(sub.begin(), sub.end());
      sort(A.begin(), A.end());
      if (sub == A) check = 1;
    }
    if (check == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return;
}
int32_t main(int32_t argc, const char *argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed;
  std::cout << std::setprecision(8);
  solve();
  return 0;
}
