#include <bits/stdc++.h>
using namespace std;
long long int pows(long long int a, long long int n, long long int m) {
  long long int res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * a) % m;
      n--;
    } else {
      a = (a * a) % m;
      n = n / 2;
    }
  }
  return res % m;
}
bool matching(string s, string t) {
  const int p = 31;
  const int m = 1e9 + 9;
  int S = s.size(), T = t.size();
  vector<long long> p_pow(max(S, T));
  p_pow[0] = 1;
  for (int i = 1; i < (int)p_pow.size(); i++) p_pow[i] = (p_pow[i - 1] * p) % m;
  vector<long long> h(T + 1, 0);
  for (int i = 0; i < T; i++)
    h[i + 1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % m;
  sort(s.begin(), s.end());
  long long h_s = 0;
  for (int i = 0; i < S; i++) h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % m;
  for (int i = 0; i + S - 1 < T; i++) {
    long long cur_h = (h[i + S] + m - h[i]) % m;
    if (cur_h == h_s * p_pow[i] % m) return true;
  }
  return false;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
bool isprime(long long int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s, p;
    cin >> s >> p;
    if (s.length() > p.length()) {
      cout << "NO" << endl;
    } else {
      int flag = 0;
      int sa = p.length() - s.length();
      for (int i = 0; i <= sa; i++) {
        string h1 = p.substr(i, s.length());
        string h2 = s;
        sort(h1.begin(), h1.end());
        sort(h2.begin(), h2.end());
        if (h1 == h2) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
}
