#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string A, B;
    cin >> A;
    cin >> B;
    sort(A.begin(), A.end());
    bool check = false;
    for (int i = 0; i < (int)B.size() - (int)A.size() + 1; ++i) {
      string tmp = B.substr(i, (int)A.size());
      sort(tmp.begin(), tmp.end());
      if (tmp == A) {
        check = true;
        break;
      }
    }
    if (check)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
  return 0;
}
