Infinite Replacement solution codeforces
You are given a string, consisting only of Latin letters ‘a’, and a string , consisting of lowercase Latin letters.
In one move, you can replace any letter ‘a’ in the stringwith a string . Note that after the replacement string might contain letters other than ‘a’.
You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
Two strings are considered different if they have different length, or they differ at some index.
The first line contains a single integer( ) — the number of testcases.
The first line of each testcase contains a non-empty string, consisting only of Latin letters ‘a’. The length of doesn’t exceed .
The second line contains a non-empty string, consisting of lowercase Latin letters. The length of doesn’t exceed .
For each testcase, print the number of different strings -1. Otherwise, print the number.that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print
3 aaaa a aa abc a b
1 -1 2
In the first example, you can replace any letter ‘a’ with the string “a”, but that won’t change the string. So no matter how many moves you make, you can’t obtain a string other than the initial one.
In the second example, you can replace the second letter ‘a’ with “abc”. Stringbecomes equal to “aabc”. Then the second letter ‘a’ again. String becomes equal to “aabcbc”. And so on, generating infinitely many different strings.
In the third example, you can either leave stringas is, performing zero moves, or replace the only ‘a’ with “b”. String becomes equal to “b”, so you can’t perform more moves on it.