Back

I. Counting Cows Again and Again

Worth 6 point(s) - Runtime Limit: 3 seconds

Summary

When farmer Jack counts the cows each day, for each group of five cows, he draws four vertical lines on his notepad, and then crosses the four with a diagonal line, as illustrated below:

IIII IIII IIII III

We can represent one of his daily entries as a string as follows: IIII/ IIII/ IIII/ III, using capital ’i’ characters and forward slash characters with exactly one space character between the groups.
The total in the above examples is 18 cows.
Given such a String, can we determine if it follows the counting rules described above?

Input

The first line of input contains a single decimal integer P,(1 ≤ P ≤ 500), which is the number of datasets that follow. Each dataset should be processed identically and independently.
Each dataset consists of a single line of text containing the problem number, K, beginning with 1, and then the string from Joe’s notebook. A correctly formatted string contains some number of groups of five, separated by single spaces, and then between one and four ‘I’ characters for the final group.
A group of five begins with exactly four ‘I’ (capital i) characters and is followed by a ‘/’ character.
Joe has no more than 500 head of cattle.

6
1 IIII/ IIII/ IIII/ III
2 IIII/ IIII/ III/ IIII/
3 /IIII /IIII III
4 IIII/ IIIII/ IIII/
5 IIII/IIII/ IIII/ III
6 iiii/ iiii/ iiii/ iii

Output

For each dataset, output a single line of text that begins with the problem number and then one of two strings. If Joes’s data is correctly formatted output “OK” followed by a space and then the total number of cows. Otherwise, output the string “Faulty format”.

1 OK 18
2 Faulty format
3 Faulty format 
4 Faulty format
5 Faulty format
6 Faulty format