First Love!!!

It is now a very difficult time now for Arif as he is coming back to Bangladesh from USA after four long years. He knows that he will meet his first love here again (He knows he will, that is his destiny) but does not know what to do. At first he plans not to recognize her, but then realizes that it is the only face he recognizes well. (Arif, is a genius programmer working in IBM, his colleagues love him very much as he solves so many difficult problems in minutes. But his problem is that he cannot remember people’s name or even face.) So he decides that he will recognize her and present her the same necklace (looks same of course) he presented her 4 years ago. His memory betrays him again as he fails to remember how the necklace looked like. Below you can see pictures of different necklaces. After thinking for along time he remembers the different type of beads that the necklace had, he also remembers the length of the necklace but fails to remember the pattern of beads (The frequency of different types of beads and their ordering). Arif is very rich now and so he decides to buy a long string of beads from which he will be able to cut away any pattern of necklace. Help Arif to solve this problem, because, in solving problems related to his first love he is still very nervous and inefficient. Remember that the bead string ABBB and BBBA are not the same because the beads are not always symmetric. There are also some other reasons which are not worth mentioning here. Input The input file contains several lines of input. Each line contains a string and an integer separated by a single space. The string contains different alpha numerals, which denote the different types of beads the necklace have. The length of this string is less than five. The next integer N (0 < N ≤ 20) denotes the length of the necklace or the number of beads of in the necklace. Output For each line of input produce two lines of output. On the first line you will have to print the minimum length of the bead string that Arif will buy. If the length of the bead string is less than 10001 you will have to print the bead string on the next line. If its length is greater than 10000 then print the line ‘TOO LONG TO PRINT.’ instead. Sample Input 10 3 ABC 9 Sample Output 10 1110001011 19691 TOO LONG TO PRINT.