

The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains three space-separated integers, 'N', 'M' and 'K', denoting the number of cities, the number of bidirectional roads, and the number of cities that Mr. X will visit, respectively.
The second line of each test case contains 'N' space-separated strings denoting the elements of the array 'ARR'.
The third line of each test contains the special string 'S'.
The next 'M' lines of each test case contain the description of the 'M' roads.
The 'i'th' line contains two space-separated integers, 'City1', 'City2'. 'City1' and 'City2' denote the two cities that are connected by the 'i'th' road.
For each test case, the checker will print "valid" if the returned order of cities results in a string that differs from the lucky string 'S' at the minimum possible places. Otherwise, the checker will print "invalid".
Print the output of each test case in a new line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
2 <= N <= 1000
1 <= M <= min(1000,(N*(N-1))/2)
1 <= K <= 100
|ARR[i]| = 3
|S| = 3*K
0 <= City1, City2 <= N-1
Every city is reachable from every other city, any two cities are directly connected by at most one road and all the input strings contain uppercase English letters only.
Where 'T' denotes the number of test cases, 'N' denotes the number of cities, 'M' denotes the number of roads, 'K' denotes the number of cities that Mr. X will visit, ARR[i] denotes the 'i'th' element of the array 'ARR', 'S' denotes the lucky string, 'City1' and 'City2' denotes the two cities that are connected by the 'i'th' road, .
Time Limit : 1 sec
The idea is to use a recursive approach to generate all the possible orders of cities that Mr. X should visit and select the best path. The recursive idea is very clear that if Mr. X visits any city on the i'th day, then he can go to any of the cities connected to that city on the (i+1)'th day. Using this idea, we can generate all the possible order of cities Mr. X can visit. After generating the corresponding special string for a particular path, we will count the number of places the generated string differs with the lucky string. In the end, we will select the path for which the generated string differs with the lucky string at the least possible places.
In the previous approach, the function generateOrder(i, j, currentDifference, currentOrder) is recursively being calculated several times for the same values. So, here we can use the technique of memoization to optimize the working of the previous approach. We will create a 2D Matrix to store all the previously computed values so that no value is being calculated multiple times.
In the first approach, the function generateOrder recursively generates all the possible paths, which has many overlapping subproblems. i.e. a recursive function computes the same sub-problems again and again. So we can use Dynamic Programming to overcome the overlapping subproblems.