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.

murli01 | 343 |

decoder_101 | 216 |

Sulagna | 189 |

kya_bolti_public | 172 |

madhursengar24 | 172 |

PiyushPandey4 | 717 |

john_wick | 681 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

jagrit_ | 507 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.