for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    res=0
    k=-1
    for i in range(1,n):
        if l[i-1]*l[i]<0:
            res=res+max(l[k+1:i])
            k=i-1
    if k<n:
        res=res+max(l[k+1:])
    print(res)
    
