What is wrong in my code , question link-> (https://www.codechef.com/MARCH20B/problems/CHPINTU)

t=int(input())
for g in range(t):
n,m=map(int,input().split())
f1=list(map(int,input().split()))
p1=list(map(int,input().split()))
ans=999
u=0
for i in range(1,m+1):
s1=0
for j in range(n):
if(f1[j]==i):
u=True
s1+=p1[j]

    if(u):
        ans=min(s1,ans)
print(ans)

Please reformat the code or post a link to your answer instead as it is not understandable.
As I can somewhat understand from your code that you are collecting the prices of baskets of each type of fruits and checking if its minimum upto now. I would recommend using a dict to store the combined prices of each fruit basket and then print out the minimum of it.