Help me in solving EQUALELE problem

My issue

t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))

new_lst =[]
for i in l:
    new_lst.append(l.count(i))

max_val = max(new_lst)
print(n - max_val) 

My code

# cook your dish here
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))

    new_lst =[]
    for i in l:
        new_lst.append(l.count(i))

    max_val = max(new_lst)
    print(n - max_val)

Learning course: Arrays, Strings & Sorting
Problem Link: Equal Elements Practice Problem in - CodeChef
when I run it is running successfully but when I submit this page showing time out. if any one can help me on this problem.

@ajit1986
plzz refer the following c++ code for better understanding of the logic

#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	// your code goes here
		int t,i;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    for(i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    int count=1;
	    
	    sort(a,a+n);
	    int ans=0;
	    
	    for(i=1;i<n;i++){
	        if(a[i]==a[i-1])
	        {
	        count++;
	        }
	        else
	        {
	            ans=max(ans,count);
	            count=1;
	        }
	    }
	    ans=max(ans,count);
	    cout<<n-ans<<endl;
	    
	}
	return 0;
}