#include <bits/stdc++.h>
using namespace std;
void solve() {
  string p, h;
  cin >> p >> h;
  long long n = p.size();
  string x, y;
  x = p, y = h;
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if (p.size() > h.size()) {
    cout << "NO\n";
    return;
  } else if (x == y) {
    cout << "YES\n";
    return;
  } else {
    for (int i = 0; i < h.size(); i++) {
      string a = h.substr(i, n);
      sort(a.begin(), a.end());
      if (a == x) {
        cout << "YES\n";
        return;
      }
    }
    cout << "NO\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
