for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    pos = 0
    neg = -10000000000
    ans = []
    for i in a:
        if i>0:
            if neg!=-10000000000:
                ans+=[neg]
            pos = max(pos,i)
            neg = -10000000000
        if i<0:
            if pos:
                ans+=[pos]
            pos = 0
            neg = max(neg,i)
    if pos:
        ans+=[pos]
    if neg!=-10000000000:
        ans+=[neg]
    print(sum(ans))