You are given two words x and y, together with a series of k words (w1,w2,…,wk). The operation w⊕wi appends the series word wi (1≤i≤k) to the end of the word w (concatenation): it writes wi immediately after w.
By appending series words to the ends of x and y (using any word as many times as you like, on either word), decide whether the two words can be made identical. If it is possible, output the minimum number of ⊕ operations required; otherwise output NIE ("no" in Polish).
For example, the words abba and ab can be equalized using the series baaabad, aa, badccaa, cc: append aa and badccaa to abba, and append baaabad, then cc, then aa to ab. Both become abbaaabadccaa, using 2+3=5 operations in total.
The first line contains a positive integer k (1≤k≤40), the length of the series. The second and third lines contain the descriptions of x and y. The next k lines contain the descriptions of w1,w2,…,wk, one per line. Each description consists of the word's length (a natural number) and the word itself, separated by a single space. Every word consists only of lowercase letters a to z and has length at most 2,000. The total length of all given words is at most 5,000.
If x and y can be equalized, output the minimum number of ⊕ operations (a nonnegative integer). Otherwise, output NIE.