#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int a[maxn];
char s[maxn];
char s1[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s + 1);
    scanf("%s", s1 + 1);
    map<char, int> Q;
    Q.clear();
    for (int i = 1; i <= strlen(s + 1); ++i) {
      Q[s[i]]++;
    }
    map<char, int> W;
    int flag = 1;
    int f = 0;
    if (strlen(s1 + 1) < strlen(s + 1)) {
      cout << "NO" << endl;
      continue;
    }
    for (int i = 1; i <= (strlen(s1 + 1) - strlen(s + 1) + 1); ++i) {
      flag = 1;
      W.clear();
      for (int j = i; j <= i + strlen(s + 1) - 1; ++j) {
        W[s1[j]]++;
      }
      for (int j = i; j <= i + strlen(s + 1) - 1; ++j) {
        if (W[s1[j]] != Q[s1[j]]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        f = 1;
        break;
      }
    }
    if (f)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
