t=int(input())
for j in range(t):
    n=int(input())
    l=list(map(int, input().split()))
    s=l[0]
    last_added=l[0]
    for i in range(1,n):
        if l[i]>0 and l[i-1]>0: 
            if l[i]>last_added:
                s=s-last_added+l[i]
                last_added=l[i]
            else:
                continue
        elif l[i]<0 and l[i-1]<0:
            if l[i]>last_added:
                s=s-last_added+l[i]
                last_added=l[i]
            else:
                continue
        else:
            s=s+l[i]
            last_added=l[i]
    print(s)