t=int(input()) for tcase in range(t): a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() s=0 for i in range(0,a[1]): s+=b[i] print(s-a[0] if s-a[0]>=0 else 0)