#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long int lcm(long long int x, long long int y) {
  return ((x * y) / gcd(x, y));
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  for (long long int i = 2; i < n; i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a = 0;
    string s, k, u;
    cin >> s >> k;
    u = k;
    if (k.length() < s.length()) {
      cout << "NO\n";
      continue;
    }
    sort(s.begin(), s.end());
    for (long long int i = 0; i < k.length() - s.length() + 1; i++) {
      k = u;
      sort(k.begin() + i, k.begin() + (i + s.length()));
      for (long long int j = 0; j < s.length(); j++) {
        if (s[j] != k[i + j]) break;
        if (j == s.length() - 1) {
          cout << "YES\n";
          a = 1;
          break;
        }
      }
      if (a == 1) break;
      if (i == k.length() - s.length()) cout << "NO\n";
    }
  }
  return 0;
}
