import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    neg,pos=0,0
    sum1=0
    mini=-math.inf
    maxi=0
    for i in range(len(a)):
        if a[i]<0:
           ##print(a[i])
           mini=max((mini),(a[i]))
           ##print(max(-1000,-1))
           ##print(mini)
           sum1+=maxi
           maxi=0
        if a[i]>0:
            maxi=max(maxi,a[i])
            if mini!=-math.inf:
                 sum1+=mini
            mini=-math.inf
    ##print(mini,maxi)
    ##print(mini)
    if a[len(a)-1]<0 and a[len(a)-2]<0:
        ##print(sum1,mini)
        sum1+=mini
        print(sum1)
        continue
    if a[len(a)-1]>0 and a[len(a)-2]>0:
        sum1+=maxi
        print(sum1)
        continue
    else:
        sum1+=a[len(a)-1]
    print(sum1)






