t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int,input().split()))
    flag = A[0]//abs(A[0])
    tmp = A[0]
    res = 0
    for i,a in enumerate(A[1:]):
        if a*flag>0:
            if a>tmp:
                tmp = a
        else:
            flag = -flag
            res+=tmp
            tmp = a
    res+=tmp
    print(res)