for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    maxi=0
    mini=-1000000000
    count=0
    if a[0]>0:
        fg=0
    else:
        fg=1
    for i in range(n):
        if a[i]>0 and fg==1:
            count+=mini
            maxi=0
        if a[i]>0:
            maxi=max(maxi,a[i])
            fg=0
        if a[i]<0 and fg==0:
            count+=maxi
            mini=-1000000000
        if a[i]<0:
            mini=max(mini,a[i])
            fg=1
    if a[n-1]>0:
        count+=maxi
    else:
        count+=mini
    print(count)
            
            
        