mod=1000000007
t=input()
for kk in range(0,t):
    n,k=(int(i) for i in raw_input().split())
    l=[int(i) for i in raw_input().split()]
    l.sort()
    nCr=[0]*n
    nCr[k-1]=1
    for i in range(0,n):
        if i>=k:
            nCr[i]=((i*nCr[i-1])/(i-k+1))
    ans=0
    for i in range(0,n):
        if n-i-1<k-1:
            break
        ans=ans+l[i]*nCr[n-i-1]
    print ans%mod