Given two strings S and T, find length of the shortest subsequence in S which is not a subsequence in T. If no such subsequence is possible, return -1. A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. A string of length n has different possible subsequences.

**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 M and N where M denotes the length of first string and N denotes the length of second string.

The second line of each test case contains the two string S and T. Both string are comprised only of lower case alphabets.

**Output:**

Output the length of the shortest uncommon subsequence for each test case in a new line. If no such sub sequence is possible print -1.

**Constraints:**

1<= T <=100

1<= N,M <=500

**Example:**

**Input:**

1

5 5

babab babba

**Output:**

3

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.

VivSisMMM | 164 |

d_Coder00 | 163 |

ajayjadhav35 | 153 |

Astikeysingh | 148 |

Sathvik Avasarala | 143 |

Pulkit__Sharma__ | 658 |

Anirban166 | 565 |

abducodes | 542 |

Sathvik Avasarala | 506 |

Found_me | 494 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.