#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
long long power(long long x, long long y) {
  long long res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
bool compare(const pair<int, int>& i, const pair<int, int>& j) {
  if (i.first != j.first)
    return i.first < j.first;
  else
    return i.second < j.second;
}
int main() {
  int t;
  cin >> t;
  string pass, hash;
  while (t--) {
    cin >> pass;
    cin >> hash;
    vector<int> counts(26, 0);
    for (int i = 0; i < pass.length(); i++) counts[pass[i] - 'a']++;
    bool con;
    for (int i = 0; i < hash.size(); i++) {
      vector<int> temp = counts;
      bool pres = true;
      con = false;
      for (int j = i; j < i + pass.size(); j++) {
        if (temp[hash[j] - 'a'] <= 0) {
          pres = false;
          break;
        } else {
          temp[hash[j] - 'a']--;
        }
      }
      if (pres) {
        con = true;
        break;
      }
    }
    if (con)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
