BVAAN - Balika Vadhu and Alok Nath

Anandi and Jagya were getting married again when they have achieved proper age. Dadi Sa invited Alok Nath to do the kanyadaan and give blessings. Alok Nath has 2 blessings. Each blessing is in the form of a string consisting of lowercase characters (a-z) only. But he can give only one blessing of K length because some priest told him to do so. Thus he decides to generate a blessing using the other two blessings. While doing this he wants to ensure that happiness brought into their life by his blessing is maximum.

The generated blessing is a common subsequence of length K of the two blessings he has. Happiness of the blessing he generates is calculated by the sum of ASCII values of characters in the blessing and he wants the happiness to be maximum. If he is not able to generate a common subsequence of length K then the happiness is 0 (zero). Alok Nath comes to you and asks you to find the maximum happiness that can be generated by the two blessings he has.

Input

First line consists of the number of test cases t. Each test case consists of two strings b1 (blessing 1), b2 (blessing 2) and an integer K, each of them in separate lines.

Output

Output consists of t lines each containing an integer denoting the maximum happiness value that can be generated by the two blessings.

Constraints

1 ≤ t ≤ 50
1 ≤ length(b1), length(b2) ≤ 100
1 ≤ K ≤ 100

Sample

Input:
2
asdf
asdf
3
anandi
jagya
3

Output:
317
0

Added by:Sanket Singhal
Date:2015-02-18
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 JS-MONKEY
Resource:Own Problem(CQM -8 BIT Mesra)

hide comments
2015-04-01 21:28:10 happy
@sanket singhal getting wa
submission id-14004895

finally accepted

Last edit: 2015-04-02 06:19:12
2015-03-27 11:22:56 Sushovan Sen
Is it common subsequence or substring?
2015-03-16 16:15:00 noobe
Please can you help me with my solution id 13874223 and please tell me the test case for which it's going wrong.
2015-03-14 21:15:40 Naman Goyal
Can it be better than (nmK)? My solution of O(nmK) is giving TLE.
EDIT: Never mind, silly mistake in recursion. Nice and easy problem otherwise.

Last edit: 2015-03-16 06:18:02
2015-03-14 10:25:17 TLE
i dont know why i am getting wrong answer plz tell my id=13855131
2015-03-13 15:19:02 kelaseek
nice
2015-03-08 10:29:37 Kshitij Agarwal
Please provide some more test cases
2015-03-07 18:03:38 ADITYA PRAKASH
please provide some corner cases
2015-03-05 09:19:22 Pulkit Singhal
Easy One :)
2015-03-01 20:29:01 MaHmOuD.
@Sanket Singhal Can u give me more test cases, please?!
My submission 13760173.

Update: AC. :)

Last edit: 2015-03-01 21:04:36
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.