for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    m=0
    mi=-9999999999999999999999999999
    s=0
    for i in range(n):
        if(a[i]>0):
            m=max(m,a[i])
            if(mi!=-9999999999999999999999999999):
                s+=mi
            mi=-9999999999999999999999999999
        else:
            mi=max(mi,a[i])
            if(m!=0):
                s+=m
            m=0
    if(mi!=-9999999999999999999999999999):
        s+=mi
    if(m!=0):
        s+=m
    print(s)
            