

1. There may be multiple occurrences of any book.
2. book1 and book2 are present on the bookshelf.
3. The name of the books is in lower-case.
4. book1 is not equal to book2.
The first line of input contains an integer ‘T’, denoting the number of test cases. The test cases follow.
The first line contains integer ‘N’, which denotes the number of books on the bookshelf.
The second line contains the names of N books in order.
The third line contains 2 words, the name of ‘book1’, and ‘book2’.
For each test case, print the minimum distance between ‘book1’, and ‘book2’.
Print the output of each test case in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1<= T <= 50
2 <= N <= 10^4
1 <= arr[i].length <= 10^4
All strings consist of lowercase letters only.
Where ’T’ is the number of test cases, and N denotes the number of elements in the array ‘arr’, arr[i] denotes the element at index ‘i’.
Time Limit: 1 sec
The idea is to traverse over all the elements in the array ‘arr’ in two nested loops. Whenever we get a ‘book1’ and ‘book2’, take the minimum of answer and the current distance.
Algorithm:
The idea is to get all the indices where ‘book1’ and ‘book2’ are present and store the indices in an array. Both the arrays will already be sorted as we found the indices by iterating over the array. Then we will use the two-pointer approach to find the minimum distance between ‘book1’ and ‘book2’.
Algorithm: