Unbroken Strings

0

0 votes
Medium
Problem

Chhaya likes to read newspaper published in Hindustan Times. Its heading is r1, it consists of lowercase Latin letters. Chhaya wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After Chhaya erases several letters from this string in order to get a new word r2. It is considered that when Chhaya erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.

For example, let's say the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac". If we erase the letters on positions 2 and 4, we get a word "acbc".

Chhaya needs to find the least number of newspaper headings r1 that are needed to glue together and erase several letters to get word r2.
Can you help Chhaya to find the solution of this problem?

Input:

The first line of input contains an integer T denoting the number of test cases and the description of T test cases are as follows:-
The first line contain the heading r1, the second line contains the word r2. The lines only consist of lowercase Latin letters .

Output:

If it is impossible to get the word r2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings r1, which Chhaya will need to receive the word r2.


Constraints:

1 ≤ T ≤ 10
1 ≤ |r1| ≤ 104
1 ≤ |r2| ≤ 106

Probelm setter:  Mahima Singh

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the 1st example, r2 ('xyz') can never be formed by glueing any number of r1 ('abc') together so output is -1.
In the 2nd example, two newspaper headings i.e. r1 ('abcd') are glued together which gives us 'abcdabcd' and now letters at position {1,2,3,8} are erased to get r2 ('dabc').
In the 3rd example, five newspaper headings i.e. r1 ('ab') are glued together which gives us 'ababababab' and now letters at position {1,6,8} are erased to get r2 ('babaaab').
In the 4rth example, six newspaper headings i.e. r1 ('ab') are glued together which gives us 'abababababab' and now letters at position {1,4,6,9,12} are erased to get r2 ('baaabba').

Editor Image

?