t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    ind=[0]
    j=1
    while(j<n):
        if(a[j]*a[j-1]<0):
            ind.append(j)
        j+=1
    s=0
    for k in range(len(ind)-1):
        r=max(a[ind[k]:ind[k+1]])
        s+=r
    b=len(ind)-1
    c=max(a[ind[b]:n])
    s+=c
    print(s)