Challenge for Sanket

3.5

15 votes
Easy
Problem

Sanket being a stud, wants to gift chocolates on "Chocolate Day" to a girl. He has N chocolates of different types. The chocolates are numbered from 1 to N. There are K types of chocolates, numbered from 1 to K. Also, there are infinite chocolates of each type. But, the girl is very demanding. She wants all chocolates of same type.

It takes one minute to change chocolate of one type to another type. Your task is to change some chocolates (possibly zero) so that all chocolates are of same type.

Given the initial types of all the chocolates, find the minimum amount of time you need to fulfill your task.

Sanket asks for your help!

Input format

The first line of input contains one integer T denoting the number of test cases.

The first line of each test case contains two space separated integers N and K.

The second line of each test case contains N space separated integers denoting initial types of the chocolates.

Output format

Output one integer per line for each test case, the minimum amount of time required to get all chocolates of same type.

Constraints

  • 1<=T<=2104
  • 1<=N<=105
  • 1<=K<=10
  • 1<= initial types of chocolates <=K
  • sum of N over all test cases <=5105

*Note : There is no partial scoring for this problem *

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We want the third chocolate of type 1 which takes one minute

Editor Image

?