Ishaan's birthday is coming. His friend Charul decides to gift him uppercase English Alphabets. Since Ishaan likes being organised, he doesn't like different alphabets. He wants to make all the alphabets same.

To exchange an alphabet with another, it costs him the difference in their ASCII value. For example, to exchange A with C, it will cost him 67-65 = 2.

He doesn't want to spend to much money, so help him calculate the minimum amount he must spend to make all the alphabets same.

**Input : **

First line of input contains a single integer T denoting the number of test cases.

The only line contains 26 space-separated integers denoting the number of alphabets. The first integer denotes the number of A's, second denotes number of B's and so on.

**Output : **

For each test case, print the required answer in a new line.

**Constraints : **

1 <= T <= 200

1 <= Total number of alphabets <= 26*(10^5)

**Example :
Input : **

3

2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3 4 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

6

3

45

**Explanation :
Case 1 : **

Exchanging all the alphabets to B will cost the minimum.

Exchanging 2 A's for B's : 2 * (66-65) = 2

Exchanging 4 C's for B's : 4 * (67-66) = 4

Total cost = 6

**Case 2 : **

Exchanging all the alphabets to C will cost the minimum.

Exchanging 3 B's for C's : 3 * (67-66) = 3

Total cost = 3

**Case 3 : **

Exchanging all the alphabets to B will cost the minimum.

Exchanging 3 A's for B's : 3 * (66-65) = 3

Exchanging 6 I's for B's : 6 * (73-66) = 42

Total cost = 45

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.