t=int(input())
ans=[]
for i in range(t):
    n=int(input());arr=list(map(int,input().split()))
    l=1;k=0
    for j in range(1,n):
        if arr[k]*arr[j]<0:
            l+=1;k=j
    na=[]
    a=0
    k=0
    while k<n:
        t=k+1
        while t<n:
            if arr[k]*arr[t]<0:break
            t+=1
        na.append(arr[k:t])
        k=t
    for k in na:
        a+=max(k)
    ans.append(a)
print(*ans,sep='\n')