407712: GYM102881 A Officer Anany Collecting String Subsequences
Description
Anany is now serving in the army. Although he is an officer, in the first a few days, he is enlisted as trooper under training. The officer in charge of his training is the officer Mohamed Yasser. Mohamed Yasser gives Anany an exercise that he must do every morning. Anany has to walk on a string of characters. He must collect one 'A', then one 'B', then one 'C', ..., and finally one 'Z' in $$$\textbf{alphabetical order}$$$.
As you know, Anany is lazy, which is why fate brought him to the military service. In order to minimize his walking distance, he wants to move forward only in the smallest possible substring. That is, he wants to find the smallest substring that contains all the characters in the alphabet $$$[A-Z]$$$ as a subsequence. Find only the length of that substring; you should let Anany depend on himself to find it.
InputThe first line of the input contains an integer $$$T$$$ $$$(1 \leq T \leq 44)$$$, the number of testcases.
The first line of each testcase contains an integer $$$n$$$ $$$(26 \leq n \leq 777)$$$, the length of the string.
The second line contains a string $$$s$$$ consisting of uppercase English letters $$$(|s| = n)$$$.
OutputFor each test case, output one integer denoting the length of the shortest substring that contains all the characters in the alphabet $$$[A-Z]$$$ as a subsequence. It's guaranteed that there exist at least one such substring.
ExampleInput3 35 FORCESABCDEFDIVGHIJKLMNOPQRSTUVWXYZ 34 ABCDEFDIVGHIJKLMNICPCOPQRSTUVWXYZO 39 AINBSHAMSCPCDEFGHIJKLMANANYOPQRSTUVWXYZOutput
29 33 39Note
In the first test case, the solution is the substring $$$s[13 \dots 41]$$$:
"ABCDEFDIVGHIJKLMNOPQRSTUVWXYZ".