아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Another FizzBuzz Task

면접 대비

시간 제한2초메모리 제한512 MB

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

보통10점 중 5점

유형
문자열, 문자열 매칭, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 (1≤N≤201 \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.

예제1

  1. 예제 1

    입력
    6
    1
    78Fizz
    68FizzBuzz71
    FizzBu
    uzzBuz
    987654321
    
    예상 출력
    1
    16
    208
    18
    -1
    8358189296