t = int(input())
for _ in range(t):
    n = int(input())
    *temparr ,= map(int,input().split())
    arr = []
    temp = temparr[0]
    flag = False
    if temp>=0:
        flag = True
    for i in range(1,n):
        check = False
        if temparr[i]<0 and (not flag):
            temp = max(temp,temparr[i])
        
        elif temparr[i]>=0 and flag:
            temp = max(temp,temparr[i])
        
        else:
            arr.append(temp)
            temp = temparr[i]
            if temp<0:
                flag = False
            else:
                flag = True
    else:
        arr.append(temp)
    print(sum(arr))