for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    x = l[0]
    sol = 0
    for i in range(1,n):
        if (l[i-1]<0 and l[i]<0) or (l[i-1]>0 and l[i]>0):
            x = max(l[i],x)
        else:
            sol+=x
            x=l[i]
    sol+=x
    print(sol)