#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string p;
    cin >> p;
    map<char, int> mapa;
    for (int i = 0; i < p.size(); i++) {
      mapa[p[i]]++;
    }
    string h;
    cin >> h;
    map<char, int> mapa2;
    if (p.size() > h.size())
      cout << "NO"
           << "\n";
    else {
      int dif = h.size() - p.size();
      bool aux;
      while (dif >= 0) {
        for (int j = 0; j < p.size(); j++) {
          mapa2[h[j]]++;
        }
        aux = 1;
        for (char c = 'a'; c <= 'z'; c++) {
          if (mapa[c] != mapa2[c]) {
            aux = 0;
            break;
          }
        }
        for (char c = 'a'; c <= 'z'; c++) {
          mapa2[c] = 0;
        }
        if (aux == 1) {
          cout << "YES"
               << "\n";
          break;
        }
        int lon = h.size();
        h = h.substr(1, lon - 1);
        dif--;
      }
      if (aux == 0)
        cout << "NO"
             << "\n";
    }
  }
  return 0;
}
