import math
for t in range(input()):
    n=input()
    l=map(int,raw_input().split())
    temp=[l[0]]
    ans=0
    for i in range(1,n):
        if l[i] > 0 and temp[0]>0:
            temp.append(l[i])
        elif l[i]<0 and temp[0]<0:
            temp.append(l[i])
        else:
            ans+=max(temp)
            temp=[l[i]]
    ans+=max(temp)
    print ans