var
p,l1,l2,i,t,n,time:longint;
v:boolean;
s1,s2:string;
begin
assign(input,'dna.in'); reset(input);
assign(output,'dna.out'); rewrite(output);
readln(time);
randomize;
for t:=1 to time do
begin
readln(s1);
readln(s2);
l1:=length(s1);
l2:=length(s2);
p:=0;
v:=true;
for i:=1 to l2 do
begin
if pos(s2[i],s1)>=p then p:=pos(s2[i],s1)
else begin
writeln(-1);
v:=false;
break;
end;
end;
if not v then continue;
writeln(random(2*l2));
end;
close(input);
close(output);
end.