Given two string **X** and **Y**. The task is to find the length of longest subsequence of string X which is substring in sequence Y.

**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 N and M denoting the length of strings X and Y.

The second line of each test case contains the two strings X and Y. The strings X and Y consist of only lower case english alphabets.

**Output:**

Output the length of the longest subsequence of string X which is also a substring of Y. Print the answer in a new line for each test case.

**Constraints:**

1<= T <=100

1<= N, M <=1000

**Example:**

Input:

1

4 8

abcd bacdbdcd

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.

PandurangMM | 60 |

codersanjeev | 56 |

BoggavarapuRamSaranSaiSrinivasGupta | 46 |

rajupraaa1234 | 45 |

bruceewayne | 44 |

mr_kksparrow | 433 |

manvirag982 | 244 |

PandurangMM | 232 |

arpit_anshuman | 228 |

SoumyaKaushik | 201 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.