Typing with scrambled keys Your friend isn't too good with computers so as a practical joke someone scrambled the letters (a-z) on his keyboard. When he sit down and tried to type his name looking at the keyboard he realized that the letters are scrambled and asked your help.

You are smart so you know that if he types his name and then repeatedly retypes what comes up on the screen instead of his name he will succeed inputting in his name eventually. You are also kind and rearrange the keys but want to know how many turns would it take to succeed.

Your task is to write a program or function that given the shuffling of the letters and the friend's name computes the number of turns.

Input details:


Two string are given as input in a structure convenient for your language.
The first string is the list of the new lowercase letters in alphabetical order of the old ones. (The first character is the one that is at the position of a, last one is  at the position of z.) Some change will always occur in the string.
The second string is the name. It could contain any printable ascii character but only the upper and lowercase alphabetical characters will be shuffled if any. The name itself might not get shuffled at al.


Output details:


Output is a single integer the number of turns minimally required. Newline is optional.


Examples:

Input:
'abcfdeghijklmnopqrstuvwxyz' 'Mr. John Doe' (d, e, f positions changed)

Output:
3 (The shown names are: Mr. John Fod => Mr. John Eof => Mr. John Doe )

Input:
'nopqrstuvwxyzabcdefghijklm' 'Mr. John Doe' (the ROT13 cipher)

Output:
2 (Any input name that contains letters will take 2 rounds to produce the original name.)

Input:
'aebcdjfghiqklmnopzrstuvwxy' 'John Doe'

Output:
140

This is code-golf so the shortest entry wins.
CJam, 31 27 25 24 bytes
l:A;lel:N{_A_$er_N#}g;],

Takes input in the form of:
aebcdjfghiqklmnopzrstuvwxy
Mr. John Doe

i.e. first line - alphabets, second line - name.
How it works:
l:A;lel:N{_A_$er_N#}g;],
l:A;                         &quot;Read the alphabets from the 1st line in A and pop from stack&quot;;
    lel:N                    &quot;Read the name in small caps from 2nd line and store in N&quot;;
         {         }g        &quot;Run a while loop until we have the original name back again&quot;;
          _                  &quot;Put a dummy string on stack just to keep count of times&quot;;
           A                 &quot;Put the alphabets on stack&quot;;
            _$               &quot;Copy them and sort the copy to get the correct order&quot;;
              er             &quot;Transliterate the right keys with the wrong ones&quot;;
                _N#          &quot;Copy the result and see if its equal to the original name&quot;;
                     ;]      &quot;Pop the last name and wrap everything in an array&quot;;
                       ,     &quot;Get the length now. Since we were putting a dummy string&quot;;
                             &quot;on stack in each iteration of the while loop, this length&quot;;
                             &quot;represents the number of times we tried typing the name&quot;;

Try it online here