import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto T = readln.chomp.to!int;

    auto A = new int[](26);
    auto B = new int[](26);

    bool ok() {
        return 26.iota.map!(i => A[i] >= B[i]).all;
    }

    while (T--) {
        A[] = 0;
        B[] = 0;
        auto P = readln.chomp;
        auto S = readln.chomp;
        if (P.length > S.length) {
            writeln("NO");
            continue;
        }
        foreach (p; P) A[p-'a'] += 1;
        foreach (i; 0..P.length) B[S[i]-'a'] += 1;
        if (ok) {
            writeln("YES");
            continue;
        }
        bool hoge = false;
        foreach (i; P.length..S.length) {
            B[S[i]-'a'] += 1;
            B[S[i-P.length.to!int]-'a'] -= 1;
            if (ok) {
                writeln("YES");
                hoge = true;
                break;
            }
        }
        if (!hoge) {
            writeln("NO");
        }
    }
}
