public static void main(String[] args)
    {

        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        for (int i = 0; i < K; i++) {
            String pattern = scanner.next();
            String source = scanner.next();

            char[] sourceChars = source.toCharArray();
            char[] patternChars = pattern.toCharArray();

            Map<Character, Integer> charMap = new HashMap<Character, Integer>(26);
            populatePattern(patternChars, charMap);

            int l = pattern.length();

            long patternHash = hash(pattern, l);
            long sourceHash = hash(source, l);

            boolean found = false;
            if ((patternHash == sourceHash) && check(sourceChars, 0, l, new HashMap<Character, Integer>(charMap))) {
                found = true;
            }

            for (int j = l; j < source.length(); j++) {
                if (found) {
                    break;
                }

                // Remove leading digit, add trailing digit, check for match.
                sourceHash = (sourceHash * inverse.get(source.charAt(j - l))) % longRandomPrime;
                sourceHash = (sourceHash * primes.get(source.charAt(j))) % longRandomPrime;

                // match
                int offset = j - l + 1;
                if ((patternHash == sourceHash) &&
                        check(sourceChars, offset, l, new HashMap<Character, Integer>(charMap))) {
                    found = true;
                }
            }

            if (found) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }