#include <bits/stdc++.h>
using namespace std;
bool match(string s1, string s2) {
  int freq1[256] = {0};
  int freq2[256] = {0};
  for (int i = 0; i < s1.length(); i++) {
    freq1[s1[i]]++;
    freq2[s2[i]]++;
  }
  for (int i = 97; i <= 122; i++) {
    if (freq1[i] != freq2[i]) {
      return false;
    }
  }
  return true;
}
int check(string pass, string hash) {
  int n = hash.length(), m = pass.length();
  for (int i = 0; i <= n - m; i++) {
    if (match(pass, hash.substr(i, m))) {
      return true;
    }
  }
  return false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string hash, pass;
    cin >> pass;
    cin >> hash;
    if (check(pass, hash)) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
