#include <bits/stdc++.h>
using namespace std;
const unsigned long long p = 31;
const unsigned long long m = 1e9 + 7;
bool compare(string a, string b) {
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int n = a.length();
  unsigned long long hash_a = 0, hash_b = 0;
  unsigned long long p_pow = 1;
  for (int i = 0; i < n; i++) {
    hash_a = (hash_a + (a[i] - 'a' + 1) * p_pow) % m;
    hash_b = (hash_b + (b[i] - 'a' + 1) * p_pow) % m;
    p_pow = (p_pow * p) % m;
  }
  if (hash_a == hash_b) return true;
  return false;
}
bool check(string a, string b) {
  int blen = b.length();
  int alen = a.length();
  for (int i = 0; i + blen - 1 < alen; i++) {
    string aux = a.substr(i, blen);
    if (compare(b, aux)) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    if (a.length() > b.length())
      cout << "NO" << '\n';
    else if (check(b, a))
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
