t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    res=[]
    res.append(l[0])
    prev=l[0]
    for i in range(1,len(l)):
        if l[i]>0 and prev>0 and l[i]>prev:
            res.remove(prev)
            res.append(l[i])
            prev=l[i]
        elif l[i] < 0 and prev < 0 and l[i] > prev:
            res.remove(prev)
            res.append(l[i])
            prev = l[i]
        elif l[i] > 0 and prev < 0 :

            res.append(l[i])
            prev = l[i]
        if l[i] < 0 and prev > 0 :

            res.append(l[i])
            prev = l[i]

    print(sum(res))
