길이가 15 이하인 문자열이 무한 FizzBuzz 문자열 F의 부분 문자열로 등장하는지 판정하고, 등장하면 처음 나타나는 위치의 1-based 인덱스를 구합니다.
보통5문자열문자열 매칭수학시뮬레이션면접 대비아직 제출이 없습니다시간 제한2초메모리 제한512 MBLet us transform the sequence of positive integers 1,2,3,… in the following way:
FizzBuzz",Fizz",Buzz"The beginning of the sequence will look as follows:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz ...
Consider the infinite string F obtained by writing this sequence without spaces. Given a string L, find whether it appears as substring of F, and if it appears, find the 1-based index of first appearance.
First line of the input contains one integer N, the number of test cases (1≤N≤20). Each of the next N lines contains one non-empty string L composed from digits and letters "F", "B", "i", "u", and "z". The length of this string does not exceed 15.
For each test case, print −1 if the given string L does not appear in F as a substring, or the smallest possible 1-based index of its first element in F if it appears.