Help me in solving STUDVOTE problem

My issue

unable to understand why the code is not working

My code

# cook your dish here
for x in range(int(input())):
    n,k = map(int,input().split())
    a= list(map(int,input().split()))
    c=[]
    for i in range(n):
        if a[i]!=i+1 and (a.count(a[i]))>=k  :
            c.append(a[i])
    print(len(set(c)))
    

Problem Link: STUDVOTE Problem - CodeChef