#include <bits/stdc++.h>
const long long INF = LLONG_MAX;
const long long MOD = 1e9 + 7;
using namespace std;
void fastio() {}
void solve() {
  string a, b;
  cin >> a >> b;
  long long na = a.size(), nb = b.size();
  long long arr[26] = {0};
  for (long long i = 0; i < na; i++) {
    arr[a[i] - 'a']++;
  }
  for (long long i = 0; i <= nb - na; i++) {
    long long drr[26] = {0};
    for (long long j = i; j < i + na; j++) {
      drr[b[j] - 'a']++;
    }
    bool state = true;
    for (long long j = 0; j < 26; j++) {
      if (arr[j] != drr[j]) state = false;
    }
    if (state == true) {
      cout << "YES" << endl;
      return;
    }
  }
  cout << "NO" << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
