for t in range(int(input())):
    n=int(input())
    a =list(map(int,input().split()))
    positive = a[0]>0
    sum=0
    maxi = a[0]
    a.append(-a[-1])
    for num in a:
        if (num>0)==positive:
            maxi = max(maxi, num)
        else:
            sum+=maxi
            maxi = num
            positive = not positive
    print(sum)