t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    p=0
    m=a[0]
    for j in range(1,n):
        if a[j]*a[j-1]>0:
            m=max(m,a[j])
        else:
            p=p+m
            m=a[j]
    p=p+m
    print(p)
            