
1. The random pointer of a node may point to NULL or to itself.
2. All the nodes will represent unique characters.
3. All the characters will be the lowercase alphabets.
4. You can assume that the first state is the first character of the string.
The first line contains a single integer 'T' that represents the number of test cases.
The first line of each test case will contain an integer ‘N’ denoting the number of states(nodes) in the state diagram.
The second line contains a string of length ‘N’ where the ith state represents the ith character of the string.
The third line contains 'N' integers a1, a2,....,an, where ai denotes the position to which the ith node’s random pointer points to. If the ith pointer points to NULL, then ai = -1.
The fourth line contains the string 'STR', which needs to be checked for the given state diagram.
Print “yes” in a single line if the string is acceptable by the given state diagram, “no” otherwise.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 < =T <= 10
1 <= N <= 26
1 <= ai <= N, or ai = -1(if pointing to NULL)
1 <= len(str) <= 10^5
Time Limit: 1 sec