k = int(input())
for j in range(k):
    n = int(input())
    a = [int(x) for x in input().split()]

    na=[a[0]]
    for i in range(1,len(a)):
        if a[i]//na[-1]<0:
            na.append(a[i])
            
        else:
            if a[i]>na[-1]:
                
                na.pop(-1)
                na.append(a[i])
    ans=0
    for i in na:
        ans+=i
    print(ans)