This page is still under construction.

Parts of this page are still being built. What you see may change.

PSU Campuses

Time limit1sMemory limit128 MB

Summary
Starting and ending at Hatyai, sum the pairwise table distances along each given campus visit order.
Level

Easy1 of 10

Topics
Simulation
Solved
No attempts yet

Problem

Prince of Songkla University (PSU) runs five campuses in the south of Thailand: Hatyai (H), Pattani (P), Suratthani (S), Phuket (K) and Trang (T). The distances between the campuses are in the table below.

CampusesDistance (km)CampusesDistance (km)
Hatyai - Pattani103Pattani - Phuket577
Hatyai - Suratthani329Pattani - Trang260
Hatyai - Phuket466Suratthani - Phuket287
Hatyai - Trang148Suratthani - Trang226
Pattani - Suratthani408Phuket - Trang312

When the president of PSU goes on a mission through several campuses, he or she wants to know the total distance of the mission. A mission always starts at the Hatyai campus, and once the mission ends the president returns from the last campus straight back to Hatyai.

Given the order of campuses of one mission, write a program that computes the total distance of that mission. The same campus can appear twice in a row, and then the distance between the two is 0.

Input

The first line contains the number of missions nn (1≤n≤1001 \le n \le 100). Each of the next nn lines describes one mission. A mission is given as a string made only of the characters H, P, S, K and T, and the president visits the campuses in the order written in that string. The Hatyai campus is always both the starting point and the end point, so H is not written at the beginning or at the end of the string. H can still appear as an intermediate campus. Each string has length between 1 and 10.

Output

For each mission print one line in the form Case i: d, where ii is the mission number starting from 1 and dd is the total distance of that mission in kilometres. Put exactly one space after the colon.

Examples1

  1. Example 1

    Input
    4
    TSK
    PHT
    PSKT
    KT
    
    Expected output
    Case 1: 1127
    Case 2: 502
    Case 3: 1258
    Case 4: 926