for i in range(int(input())):
    length = int(input())
    l = list(map(int,input().split()))
    counter,curr = 1,l[0]
    summation = 0
    for j in range(1,length):
        if (curr>0 and l[j]>0) or (curr<0 and l[j]<0):
            if curr<l[j]:
                curr=l[j]
        else:
            summation+=curr
            curr = l[j]
        if j==length-1:
            summation+=curr
    print(summation)

