t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    neg,pos = [],[]
    ans = 0
    for i in l:
        if i>0:
            pos.append(i)
            if len(neg)!=0:
                ans = ans+max(neg)
                neg = []
        else:
            neg.append(i)
            if len(pos)!=0:
                ans = ans+max(pos)
                pos = []
    if len(neg)!=0:
        ans += max(neg)
    if len(pos)!=0:
        ans += max(pos)
    print(ans)
            
