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