import java.io.*;
import java.util.*;
import java.awt.*;

public class SMS
{
    public static void main(String[] args)
    {
	Scanner input = new Scanner(System.in);
	PrintStream output = System.out;

	Map<Character, Point> number = new HashMap<Character, Point>();
	number.put(' ', new Point(-1, 1));
	number.put('A', new Point(2, 1));
	number.put('B', new Point(2, 2));
	number.put('C', new Point(2, 3));
	number.put('D', new Point(3, 1));
	number.put('E', new Point(3, 2));
	number.put('F', new Point(3, 3));
	number.put('G', new Point(4, 1));
	number.put('H', new Point(4, 2));
	number.put('I', new Point(4, 3));
	number.put('J', new Point(5, 1));
	number.put('K', new Point(5, 2));
	number.put('L', new Point(5, 3));
	number.put('M', new Point(6, 1));
	number.put('N', new Point(6, 2));
	number.put('O', new Point(6, 3));
	number.put('P', new Point(7, 1));
	number.put('Q', new Point(7, 2));
	number.put('R', new Point(7, 3));
	number.put('S', new Point(7, 4));
	number.put('T', new Point(8, 1));
	number.put('U', new Point(8, 2));
	number.put('V', new Point(8, 3));
	number.put('W', new Point(9, 1));
	number.put('X', new Point(9, 2));
	number.put('Y', new Point(9, 3));
	number.put('Z', new Point(9, 4));

	int cases = Integer.parseInt(input.nextLine());
	for (int i = 0; i < cases; i++)
	{
	    Scanner helper = new Scanner(input.nextLine());
	    int press = helper.nextInt();
	    int wait = helper.nextInt();
	    String text = input.nextLine();

	    int time = 0;
	    int previous = 0;
	    for (int j = 0; j < text.length(); j++)
	    {
		Point info = number.get(text.charAt(j));
		if (info.x == previous)
		{
		    time += wait;
		}
		time += info.y * press;
		previous = Math.max(info.x, 0); // to handle space
	    }
	    output.println(time);
	}
    }
}
