Given an array **A** of size ** N**, the array contains numbers in range from

**Input:**

The first line of input contains an integer **T**, denoting the number of test cases. T testcases follow. Each testcase contains two lines of input. First line contains **N and k**, both separated by a space. The next line contains N integers separated by spaces.

**Output:**

For each testcase, in a new line, print the maximum frequency element.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{7}

0 <= k <= N

0 <= A_{i} <= k-1

**Example:**

**Input:**

2

4 3

2 2 1 2

6 3

2 2 1 0 0 1

**Output:**

2

0

**Explanation:**

**Testcase1: **2 is the most frequent element.

**Testcase2: **0 1 and 2 all have same frequency of 2. But since 0 is smallest, we print that.

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.

_Shubham_Jain_06 | 404 |

maggiiiii | 315 |

Savage_19 | 310 |

ritikdagar0203 | 241 |

thanuvinu94 | 233 |

Bishnu Dev Panda | 810 |

_Shubham_Jain_06 | 715 |

okayboss | 652 |

maggiiiii | 598 |

Savage_19 | 576 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.