#include <bits/stdc++.h>
using namespace std;
string original, hashed;
void solve() {
  cin >> original >> hashed;
  sort(original.begin(), original.end());
  for (int i = 0, run_to = hashed.size() - original.size(); i <= run_to; i++) {
    string tester = hashed.substr(i, original.size());
    sort(tester.begin(), tester.end());
    if (tester == original) {
      printf("YES\n");
      return;
    }
  }
  printf("NO\n");
}
int main() {
  int tester;
  scanf("%d", &tester);
  while (tester--) solve();
}
