I=lambda : list(map(int,input().split()))
for _ in range(int(input())):
    n,=I()
    l=I()
    an=0;i=0;k=0;m=-10**9-1
    while i<n:
        while i<n and l[i]>0:
            #print('p',i)
            k=max(k,l[i])
            i+=1
        an+=k;k=0
        while i<n and l[i]<0:
            #print('m',i)
            m=max(m,l[i])
            i+=1
        if i<n or l[n-1]<0:
            an+=m;m=-10**9-1
    print(an)