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.

hari32147 | 128 |

RaghavaMahanthi | 100 |

AdityaRaj9 | 84 |

AtakanSarıoğlu | 83 |

geetyadav | 82 |

abducodes | 866 |

harshtyagi36 | 432 |

arpit_anshuman | 331 |

vamsikrishna55 | 323 |

sandipbhaumik | 321 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.