#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long ret = 0, t = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') t = -1, c = getchar();
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ret * t;
}
const int MAXN = 1005;
int T;
char P[MAXN], H[MAXN];
int L1, L2;
int buc1[4000], buc2[4000];
int main() {
  T = read();
  while (T--) {
    scanf("%s%s", P + 1, H + 1);
    int i, j;
    L1 = strlen(P + 1), L2 = strlen(H + 1);
    bool ans = 0;
    if (L1 <= L2) {
      for (i = 0; i < 26; ++i) buc1[i] = buc2[i] = 0;
      for (i = 1; i <= L1; ++i) ++buc1[P[i] - 'a'];
      for (i = 1; i <= L1; ++i) ++buc2[H[i] - 'a'];
      for (j = 0; j < 26; ++j)
        if (buc1[j] != buc2[j]) {
          break;
        }
      if (j >= 26) ans = 1;
      if (!ans) {
        for (i = 2; i + L1 - 1 <= L2; ++i) {
          --buc2[H[i - 1] - 'a'], ++buc2[H[i + L1 - 1] - 'a'];
          for (j = 0; j < 26; ++j)
            if (buc1[j] != buc2[j]) {
              break;
            }
          if (j >= 26) break;
        }
        if (i + L1 - 1 <= L2) ans = 1;
      }
    }
    puts(ans == 1 ? "YES" : "NO");
  }
  return 0;
}
