#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int hsh1[26], hsh2[26];
    memset(hsh1, 0, sizeof(hsh1));
    string s1, s2;
    cin >> s1 >> s2;
    int n1 = s1.length(), n2 = s2.length();
    for (int i = 0; i < n1; i++) {
      hsh1[s1[i] - 'a']++;
    }
    bool ans = false;
    for (int i = 0; i < n2; i++) {
      for (int j = i; j < n2; j++) {
        memset(hsh2, 0, sizeof(hsh2));
        for (int k = i; k <= j; k++) {
          hsh2[s2[k] - 'a']++;
        }
        bool flag = true;
        for (int i = 0; i < 26; i++) {
          if (hsh1[i] != hsh2[i]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          ans = true;
          break;
        }
      }
      if (ans) {
        break;
      }
    }
    if (ans)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
