for i in range(int(input())*2):
    z=input().split()
    z=[int(x) for x in z]
    if i%2==0:
        help = [[] for _ in range(z[0] + 1)]
    if i%2==1:
        counter = 0
        for j in range(len(z)):
            if j>0 and (z[j]>0 and z[j-1]<0) or (z[j]<0 and z[j-1]>0):
                counter += 1
            help[counter].append(z[j])
        total = 0
        for j in range(len(help)):
            if len(help[j])>0:
                total += max(help[j])
        print(total)