for i in range(int(input())):
    length = int(input())
    l = list(map(int,input().split()))
#    length = len(l)
    sec = [[l[0]]]
    s = 0
    index = 0
    for j in range(1,length):
        if sec[-1][-1]<0 and l[j]<0 or sec[-1][-1]>0 and l[j]>0:
            sec[-1].append(l[j])
        else:
            s+=max(sec[-1])
            sec.append([l[j]])
    s+=max(sec[-1])
    print(s)