#K49157. Most Frequent Character

    ID: 28580 Type: Default 1000ms 256MiB

Most Frequent Character

Most Frequent Character

Given a set of test cases, each consisting of a string, your task is to determine the character that appears most frequently in the string. In the event that multiple characters share the same highest frequency, output the lexicographically smallest character.

Details:

  • The first line of input contains an integer \(T\) denoting the number of test cases.
  • For each test case, the first line contains an integer \(N\), the length of the string, and the next line contains the string \(S\) of length \(N\).
  • For each test case, output the most frequent character on its own line.

Note: If two or more characters have the same frequency, choose the one that comes first in alphabetical order. All formulas in this problem (if any) are given in \(\LaTeX\) format.

inputFormat

The input begins with an integer \(T\) — the number of test cases. Each test case consists of the following two lines:

  1. An integer \(N\) representing the length of the string.
  2. A string \(S\) of length \(N\).

outputFormat

For each test case, output a single line which contains the character that appears most frequently in the string \(S\). In the case of a tie, output the lexicographically smallest character.

## sample
3
6
aabbcc
5
abcde
10
aabbbccddd
a

a b

</p>