Another FizzBuzz Task

길이가 15 이하인 문자열이 무한 FizzBuzz 문자열 F의 부분 문자열로 등장하는지 판정하고, 등장하면 처음 나타나는 위치의 1-based 인덱스를 구합니다.

보통5문자열문자열 매칭수학시뮬레이션면접 대비아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Let us transform the sequence of positive integers 1,2,3,1, 2, 3, \ldots in the following way:

  • if an integer is divisible by 15, it is replaced with "FizzBuzz",
  • if an integer is divisible by 3 and is not yet replaced, it is replaced with "Fizz",
  • if an integer is divisible by 5 and is not yet replaced, it is replaced with "Buzz"
  • otherwise the integer is not replaced.

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 FF obtained by writing this sequence without spaces. Given a string LL, find whether it appears as substring of FF, and if it appears, find the 1-based index of first appearance.

입력

First line of the input contains one integer NN, the number of test cases (1N201 \le N \le 20). Each of the next NN lines contains one non-empty string LL composed from digits and letters "F", "B", "i", "u", and "z". The length of this string does not exceed 1515.

출력

For each test case, print 1-1 if the given string LL does not appear in FF as a substring, or the smallest possible 1-based index of its first element in FF if it appears.