t=int(input())
while(t):
    t=t-1
    n=int(input())
    arr=list(map(int,input().split()))
    s=0
    mi=arr[0]
    ma=arr[0]
    c=-1
    for i in range(n-1):
        if arr[i]*arr[i+1]<0:
            s=s+max(arr[c+1:i+1])
            c=i
    if c<n-1:
        s=s+max(arr[c+1:])
    print(s)