def s(ar):
    x=0
    for i in range(len(ar)):
        x+=ar[i]
    return x

t=int(raw_input())
ans=[]
for i in range(t):
    n=int(raw_input())
    ar=map(int,raw_input().split())
    x=[]
    mi=[]
    ma=[]
    for j in range(len(ar)):
        if ar[j]>=0:
            ma.append(ar[j])
            if len(mi)!=0:
                x.append(max(mi))
                mi=[]
        else:
            mi.append(ar[j])
            if len(ma)!=0:
                x.append(max(ma))
                ma=[]
    if len(mi)!=0:
      x.append(max(mi))
    if len(ma)!=0:
      x.append(max(ma))
    ans.append(x)
print ans
for i in range(len(ans)):
    print s(ans[i])