Last Match
Submissions: 685   Accuracy:

39.96%

  Difficulty: Easy   Marks: 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

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Hardik Gulati
Author: hardikgulati96


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.