for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    
    b = a[0]
    #b.append(a[0])
    
    sumi = b
    
    for i in range(1,n):
        if b<0:
            if a[i]<0:
                if b<a[i]:
                    sumi+=(a[i] - b)
                    b = a[i]
            else:
                b = a[i]
                sumi+=a[i]
            continue
        if b>0:
            if a[i]>0:
                if b<a[i]:
                    sumi+=(a[i] - b)
                    b = a[i]
            else:
                b = a[i]
                sumi+=a[i]
    
    print(sumi)