# cook your dish here
for _ in range(int(input())):
    n=int(input())
    ele=list(map(int,input().split()))
    if ele[0]>0:
        sign=1
    else:
        sign=0
    max_sum=0
    sign_change_index=[0]
    for i in range(1,n):
        ele_sign=1
        if ele[i]>0:
            ele_sign=1
        else:
            ele_sign=0
        if ele_sign!=sign:
            sign_change_index.append(i)
            sign=1-sign
    sign_change_index.append(n)
    for i in range(0,len(sign_change_index)-1):
        max_sum+=max(ele[sign_change_index[i]:sign_change_index[i+1]])
    print(max_sum)
            
        
    
    