Using data compression technique, the long string ``ruiruiruiruiruirui" can be compressed into ``(ruirui)3" or ``(rui)6". To simplify the technique, multiple compressions are not allowed. For example, we don't allow to compress the string ``princessruiruiprincessruirui" into ``(princess(rui)2)2".
Now for given string $S$ and $k$ patterns using the mentioned technique, we want to distinguish each pattern which is a prefix of $S$. We emphasize that a pattern as a string can be cyclic shifted. For example, a pattern ``abcd" can be shifted into ``bcda", ``cdab" or ``dabc".