Given two strings ‘X’ and ‘Y’, find the length of the longest common substring.

Examples :

```
Input : X = "GeeksforGeeks", y = "GeeksQuiz"
Output : 5
The longest common substring is "Geeks" and is of
length 5.
Input : X = "abcdxyz", y = "xyzabcd"
Output : 4
The longest common substring is "abcd" and is of
length 4.
Input : X = "zxabcdezy", y = "yzabcdezx"
Output : 6
The longest common substring is "abcdez" and is of
length 6.
```

**Input:**

First line of the input contains no of test cases **T**,the **T** test cases follow.

Each test case consist of 2 space separated integers **A** and **B** denoting the size of string **X** and **Y** respectively

The next two lines contains the 2 string **X** and **Y**.

**Output:**

For each test case print the length of longest common substring of the two strings .

**Constraints:**

1<=T<=200

1<=size(X),size(Y)<=100

**Example:**

**Input:**

2

6 6

ABCDGH

ACDGHR

3 2

ABC

AC

**Output:**

4

1

SushmitaRaj | 61 |

svashish305 | 54 |

Mr_Bean | 49 |

deepaksh0607 | 48 |

MuhammadHasan | 43 |

kinetic | 317 |

yirans | 278 |

kevinyu102589 | 263 |

rutvik29 | 217 |

kyaba-kun | 206 |

akhayrutdinov | 4913 |

Ibrahim Nash | 4431 |

Quandray | 4261 |

sanjay05 | 3668 |

GB11 | 2857 |

Login to report an issue on this page.