for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    ans=[l[0]]
    for i in range(1,len(l)):
        if (l[i-1]<0 and l[i]>0) or (l[i]<0 and l[i-1]>0) :
            ans.append(l[i])
        else:
            ans[-1]=max(l[i],l[i-1])
    print(sum(ans))