Last Match
Easy Accuracy: 40.03% Submissions: 894 Points: 2

Given two strings A and B you need to find the last occurrence ( 1 based indexing) of string B in string A. 

Input:
first line of input contains of an integer 'T' denoting number of test cases
first line of each testcase contains String A.
Second line of each testcase contains String B.

Output:
for each case print an integer depicting the starting index of matched string ,corresponding to the answer .
print -1 if the string B is not Found in A.

 

Constarints:
1<=T<=100
1<=len(B)<=10^5
1<=len(A)<=10^6
length(A)>=length(B)


Example:

Input

2
abcdefghijklghifghsd
ghi
abdbccaeab
abc

Output:
13
-1

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.