#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  for (long long int j = 0; j < n; j++) {
    string s;
    cin >> s;
    string h;
    cin >> h;
    sort(s.begin(), s.end());
    bool found = false;
    for (long long int i = 0; i < h.size(); i++) {
      string sub = h.substr(i, s.size());
      sort(sub.begin(), sub.end());
      if (s == sub && !found) {
        cout << "YES";
        found = true;
      }
    }
    if (!found) {
      cout << "NO";
    }
    cout << '\n';
  }
  return 0;
}
