Can anyone help me to find the logical mistake due to which i am not getting the desired output?

https://www.codechef.com/viewsolution/79747683

Input:

1
a a
4
a
a
a
a

Your Output:

YES

Correct Output:

NO

in this testcase, A + B = “aa” and C = “aaaa”. C is not a substring of any permutation of A+B. Therefore the answer is NO