#include <bits/stdc++.h>
using namespace std;
bool primecheck(long long int a) {
  bool check = true;
  for (long long int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      check = false;
      break;
    }
  }
  return (check);
}
vector<long long int> printDivisors(long long int n) {
  vector<long long int> sol;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i) {
        sol.push_back(i);
      } else {
        sol.push_back(i);
        sol.push_back(n / i);
      }
    }
  }
  return (sol);
}
long long int digits(long long int a) { return (floor(log10(a)) + 1); }
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
bool check(string a, string b) {
  long long int freq1[26] = {0};
  long long int i;
  for (i = 0; i < a.size(); i++) {
    freq1[a[i] - 'a']++;
  }
  for (i = 0; i < b.size(); i++) {
    freq1[b[i] - 'a']--;
  }
  bool sol = true;
  for (i = 0; i < 26; i++)
    if (freq1[i] != 0) sol = false;
  return (sol);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, c, i, j, k, l, m, n, t;
  cin >> t;
  while (t--) {
    string num1, num2;
    cin >> num1 >> num2;
    bool sol;
    long long int size1 = num1.size();
    long long int size2 = num2.size();
    if (size2 < size1) {
      cout << "NO"
           << "\n";
    } else {
      sol = false;
      for (i = 0; i <= size2 - size1; i++) {
        string fresh = num1;
        for (j = 0; j < size1; j++) {
          fresh[j] = num2[i + j];
        }
        if (check(num1, fresh)) {
          cout << "YES"
               << "\n";
          sol = true;
          break;
        }
      }
      if (!sol)
        cout << "NO"
             << "\n";
    }
  }
}
