Limits 1s, 512 MB

A phone number is fancy if any one of the following conditions is satisfied:

  1. At least 4 consecutive digits in the given phone number are sequentially increasing. 9084567091 and 9012346709 are fancy but 9845680210 is not.

  2. At least 3 consecutive digits in the given phone number are same. Example: 9001118127.

  3. At least 2 consecutive digits in the given phone number are same, and this occurs in at least two non-overlapping places. For example: 1982243566 and 1982243522.

  4. if the frequency of any digit is at least 5. Example: 9897952399.

You are given some valid phone numbers, you need to find whether the given numbers are fancy or not. A valid phone number is always 10 digits long and does not contain leading zeros.

Input

Input starts with an integer TT (0<T2488320 < T ≤ 248832), denoting the number of test cases. Each case contains a valid phone number.

Output

For each test case, print fancy if the phone number is Fancy, otherwise print Not Fancy. Please output the result of each test case on a separate line.

Sample

InputOutput
7
9084567091
9012346709
9845680210
9001118127
9897952399
1982243522
1982243566
Fancy
Fancy
Not Fancy
Fancy
Fancy
Fancy
Fancy

Submit

Login to submit.

Statistics

83% Solution Ratio
IOI_StfuFfsEarliest, May '18
rifatrraazzFastest, 0.0s
IOI_StfuFfsLightest, 2.2 MB
Omi074Shortest, 581B
Toph uses cookies. By continuing you agree to our Cookie Policy.