#include <bits/stdc++.h>
using namespace std;
int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(long long &x) { return scanf("%lld", &x); }
int read(long long &x, long long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) {
  int r = scanf("%s", buff);
  s = buff;
  return r;
}
vector<int> getF(string s) {
  vector<int> S(300);
  for (char c : s) S[c]++;
  return S;
}
int main() {
  int TC;
  read(TC);
  while (TC-- > 0) {
    string P, H;
    read(P);
    read(H);
    bool ok = 0;
    for (int i = 0; i <= int(H.size()) - int(P.size()); ++i) {
      if (getF(P) == getF(H.substr(i, P.size()))) {
        ok = 1;
      }
    }
    cout << (ok ? "YES" : "NO") << endl;
  }
}
