n=int(input())
total=0
move=0
for i in range(n):
    t=int(input())
    for i in range(t):
        cost=0
        c,d=[int(i) for i in input().split(" ")]
        if c<3 and cost<=3:
            if move==10:
                total+=10*d
            else:
                total+=d
                cost+=c
                move+=1
print(total)    
            