A Password Policy Requirement

No attempts yetTime limit1sMemory limit128 MB

Problem

Password security is a tricky problem. Users prefer short and simple passwords that are easy to remember, but those passwords are not safe enough, so an environment with stronger security imposes a password policy. Here is one example of a password policy for a user account in a domain.

The password must be at least six characters long, and it must contain at least one character from each of the following categories.

  1. English uppercase letters (A through Z)
  2. English lowercase letters (a through z)
  3. Base 10 digits (0 through 9)

You are given a string of letters and digits. Find the length of the shortest contiguous substring of that string that satisfies the password policy above.

Input

The input contains NN test cases. The first line has one integer NN (1N501 \le N \le 50).

Each of the next NN lines holds one test case, a string of at most 200 letters and digits.

Output

Print the result of the ii-th test case on the ii-th line. Print one integer, the minimum length of a contiguous substring that satisfies the password policy. If no such substring exists, print 0.