#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    long long int l1 = s1.length();
    long long int l2 = s2.length();
    if (l1 > l2) {
      cout << "NO" << endl;
      continue;
    }
    long long int flag = 0;
    sort(s1.begin(), s1.end());
    long long int i;
    for (i = 0; i <= l2 - l1; i++) {
      string s3 = s2.substr(i, l1);
      sort(s3.begin(), s3.end());
      if (s3 == s1) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "YES" << endl;
    } else
      cout << "NO" << endl;
  }
}
