We are given a row wise sorted matrix of size r*c, we need to find the median of the matrix given. It is assumed that r*c is always odd.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case contains two integers r and c, where r is the number of rows and c is the number of columns in the array a[]. Next r line contains space separated c elements each in the array a[].

**Output:**

Print an integer which is the median of the matrix.

**Constraints:**

1<= T <=100

1<= r,c <=150

1<= a[i][j] <=1000

**Example:
Input:**

1

3 3

1 3 5

2 6 9

3 6 9

5

Author: shashwat jain

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.

hari32147 | 100 |

AtakanSarıoğlu | 83 |

geetyadav | 82 |

amitpandey19 | 81 |

AdityaRaj9 | 75 |

abducodes | 862 |

harshtyagi36 | 425 |

vamsikrishna55 | 323 |

sandipbhaumik | 321 |

arpit_anshuman | 319 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.