CORUS problem(MAY CHALLENGE 2020), not understanding why is it showing TLE errors

t=int(input())
i=0
j=0
for i in range(t):
x, y = [int(x) for x in input().split()]
s=input()
for i in range(y):
pq=0
center=int(input())
for i in range(x):
c=1
for j in range(i+1,x):
if(s[i]==s[j] and s[i]!=’ '):
c=c+1
s= s[:j] + ‘0’ + s[j+1:]
if(c>1 and s[i]!=‘0’):
if(c>=center):
pq=pq+c-center
else:
pq=pq+0
print(pq)