Help me in solving WATSCORE problem

My issue

how we can find p1 = p2 = …pn, if both are in line variable and this all are also part of a single test case

My code

# cook your dish here
t=int(input())
for i in range(t):
    n=int(input())
    for j in range(n):
        c=0
        pi,si=map(int,input().split())
        if pi > 8 :
            c =0
        else:
            if pi > si:
                c=0
            else:
                c+=si
        
    print(c)

Problem Link: WATSCORE Problem - CodeChef

@sonupal0840
U can store the max score of each problem in some datastructure like dictionary or list .
for ex
n=5
1 5
1 50
2 30
2 10
9 100
first u will put for 1->5
then u find 1 again then now 1 will give u 50 then update the value of at . now 1->50
then u find 2 . then 2->30.
then u find 2 again but now it will give u less score then previous so don,t update it.
then u will find 9 which is non scorable so ignore it.
so the answer will be 50+30=80.