#include <bits/stdc++.h>
using namespace std;
long long mp1[40], mp2[40];
int main() {
  long long n;
  cin >> n;
  while (n--) {
    string str, st;
    cin >> str;
    cin >> st;
    long long sz1 = str.size();
    long long sz2 = st.size();
    memset(mp1, 0, sizeof(mp1));
    memset(mp2, 0, sizeof(mp2));
    bool flag = false;
    for (long long i = 0; i < sz1; i++) {
      mp1[str[i] - 'a']++;
    }
    for (long long i = 0; i < (sz2 - sz1 + 1); i++) {
      memset(mp2, 0, sizeof(mp2));
      for (long long j = i; j < sz1 + i; j++) {
        mp2[st[j] - 'a']++;
      }
      bool f = true;
      for (long long k = 0; k <= 30; k++) {
        if (mp1[k] != mp2[k]) {
          f = false;
          break;
        }
      }
      if (f == true) {
        flag = true;
        break;
      }
    }
    if (flag) {
      cout << "YES" << endl;
    } else
      cout << "NO" << endl;
  }
  return 0;
}
