

Initially, he is at the first letter of the keyboard.
All letters are in lower-case English letters.
Let s = “perry”, keyboard = “qwertyuiopasdfghjklzxcvbnm”.
Now In this example, Francis will start from the first index and go to ‘p’, which will take 9 seconds, now from ‘p’ to ‘e’, the distance is of 7 indexes, from ‘e’ to ‘r’ the distance is 1, from ‘r’ to ‘r’ it will be zero, and from ‘r’ to ‘y’ the distance will be 2. Hence the total time taken is 9 + 7 + 1 + 0 + 2 = 19.
Hence the answer is 19.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains a string “keyboard” denoting the keyboard’s layout.
The second line of the test case contains a string ‘s’ denoting the secret message which needs to be sent.
For each test case, print a single integer “answer”, denoting the time taken by Francis to type the secret message.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 100
keyboard.length = 26
1 <= |S| <= 10^5, where |S| represents the length of the String S.
Time limit: 1 sec
In this approach, we will start searching every letter from the point where the last letter was located, when we find the next letter we will add the time taken to find the letter to the final answer and return the final answer.
The steps are as follows:
In this approach, we will store all the positions of the keyboard in a map/Vector of size 26 and while iterating through the string ‘s’, we will calculate the distance between the previous letter and the current letter using this map/vector.
The steps are as follows: