t=int(input())
for w in range(t):
    n=int(input())
    l=[int(i) for i in input().split()]
    a=l[0]
    s=0
    for i in l:
        if(a*i<0):
            s+=a
            a=i
        else:
            a=max(a,i)
    print(s+a)