Under construction

Still being built. Things may change

Transform the String

Memory limit1024 MB

Summary
For each test case, find the minimum number of cyclic alphabet steps needed to turn every letter of S into some letter present in F.
Level

Easy3 of 10

Topics
String, Brute force, Implementation, Greedy
Solved
No attempts yet

Problem

You are given a string SS that denotes a padlock consisting of lowercase English letters. You are also given a string FF consisting of a set of favorite lowercase English letters. You may perform several operations on the padlock. In each operation, you can change one letter of the string to the one following it or preceding it in alphabetical order. For example, for the letter c, you may change it to either b or d in an operation. The letters are considered in cyclic order, so the preceding letter for a is z, and the following letter for z is a.

Find the minimum number of operations required so that every letter in string SS after the operations is present in string FF.

Input

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case consists of two lines.

The first line of each test case contains the string SS.

The second line of each test case contains the string FF.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of operations required so that every letter in string SS after the operations is one of the characters in string FF.

Constraints

  • 1≤T≤1001≤T≤100.
  • 1≤1≤ the length of S≤105S≤10^5.
  • SS consists only of lowercase English letters.
  • FF consists only of distinct lowercase English letters.
  • The letters in string FF are sorted lexicographically.

Examples2

  1. Example 1

    Input
    2
    abcd
    a
    pppp
    p
    
    Expected output
    Case #1: 6
    Case #2: 0
    
  2. Example 2

    Input
    3
    pqrst
    ou
    abd
    abd
    aaaaaaaaaaaaaaab
    aceg
    
    Expected output
    Case #1: 9
    Case #2: 0
    Case #3: 1