Given two strings X and Y, and two values costX and costY. We need to find minimum cost required to make the given two strings identical. We can delete characters from both the strings. The cost of deleting a character from string X is costX and from Y is costY. Cost of removing all characters from a string is same.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains integers X and Y denoting the value of costX and costY.

The second line of the test case contains the two strings X and Y.

**Output:**

Print the total cost to make the two strings equal for each test case in a new line.

**Constraints:**

1<= T <=100

1<= length of strings X and Y <=1000

1<= costX, costY <=1000

**Example:**

**Input:**

1

10 20

abcd acdb

**Output:**

30

Author: sujnesh

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.

narahc321 | 170 |

agness | 163 |

lonecoder | 153 |

2016uec1342 | 142 |

HuHu | 140 |

lonecoder | 1088 |

nikhil_sojan | 1082 |

KshatriyaYash | 1066 |

mazumderrohit8 | 928 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4504 |

Quandray | 4444 |

Login to report an issue on this page.