# [Solution] Infinite Replacement solution codeforces

Infinite Replacement solution codeforces – You are given a string 𝑠s, consisting only of Latin letters ‘a’, and a string 𝑡t, consisting of lowercase Latin letters.

## [Solution] Infinite Replacement solution codeforces

In one move, you can replace any letter ‘a’ in the string 𝑠s with a string 𝑡t. Note that after the replacement string 𝑠s 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.

Input

The first line contains a single integer 𝑞q (1𝑞1041≤q≤104) — the number of testcases.

The first line of each testcase contains a non-empty string 𝑠s, consisting only of Latin letters ‘a’. The length of 𝑠s doesn’t exceed 5050.

The second line contains a non-empty string 𝑡t, consisting of lowercase Latin letters. The length of 𝑡t doesn’t exceed 5050.

## [Solution] Infinite Replacement solution codeforces

For each testcase, print the number of different strings 𝑠s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

Example
input

Copy
3
aaaa
a
aa
abc
a
b

output

Copy
1
-1
2


## Infinite Replacement solution codeforces

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”. String 𝑠s becomes equal to “aabc”. Then the second letter ‘a’ again. String 𝑠s becomes equal to “aabcbc”. And so on, generating infinitely many different strings.

In the third example, you can either leave string 𝑠s as is, performing zero moves, or replace the only ‘a’ with “b”. String 𝑠s becomes equal to “b”, so you can’t perform more moves on it.