The WSA prints every important document and stores the printouts in large, secure safes. As per policy, safes always must be closed after use, forcing employees to open each safe hundreds of times per day. A key point of optimizing processes at the WSA is to speed up entering passwords for safes.
The keyboard keys on the safe are not ordinary keys, every time they are pressed they don't just enter the letter displayed on them as input, but the letter displayed on them changes as well. For each key, there is a cycle of letters that can appear
The cycle of each key (actual letters the key would input push-by-push, in order) is known as well as the password that needs to be entered. The code is accepted only if a password of length N is entered using the last N key presses (that is, there's no way to reset cycles in between). All keys start on the first letter of their cycle (and the cycle can loop around).
The task is to find the least amount of key presses needed to enter the code.
For each keyboard there are several different passwords that the task should be solved for.
3 ABC TEST CAT 4 TEST CC STT TT
4 4 5 4