
t=int(input())
for hh in range(0,t):
    n=int(input())
    a=[int(x) for x in input().split()]
    if(a[-1]>0):
        a.append(-1)
    else:
        a.append(1)
    n+=1
    prev_pos=-2
    prev_neg=-2
    mx_pos=-1000000001
    mx_neg=-1000000001
    max_pos_set=0
    max_neg_set=0
    ans=0
    for i in range(0,n):
        if a[i]>0:
            max_pos_set=1
            if prev_pos==(i-1):
                mx_pos=max(mx_pos,a[i])
            else:
                if max_neg_set>0:
                    ans+=mx_neg
                mx_pos=a[i]
            prev_pos=i
        else:
            max_neg_set=1
            if prev_neg==(i-1):
                mx_neg=max(mx_neg,a[i])
            else:
                if max_pos_set>0:
                    ans+=mx_pos
                mx_neg=a[i]
            prev_neg=i
        # print(ans)
    print(ans)


