t=int(input())

for i in range(0,t):
    input()
    d = [int(f) for f in input().split()]

    ans=[[d[0]]]
    startPos=0
    m=0
    cnt=0
    for i in range(1,len(d)):
        if d[i] * d[i-1] > 0:
            ans[-1].append(d[i])
        else:
            ans.append([d[i]])
    s=0
    for i in ans:
        s+=max(i)
    print(s)