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.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.