#include <bits/stdc++.h>
using namespace std;
const int INF = 1e6 + 9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    string act;
    cin >> s >> act;
    map<char, int> cont;
    map<char, int> cont2;
    sort(s.begin(), s.end());
    bool can = false;
    int qtd = 0;
    for (int i = 0; i < (int)(act.size()); i++) {
      for (int j = i; j < (int)act.size(); j++) {
        string s2 = act.substr(i, j - i + 1);
        sort(s2.begin(), s2.end());
        if (s2 == s) can = true;
      }
    }
    if (can)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
