for i in range(int(input())):
    N = int(input())
    A = list(map(int,input().split()))+[0]
    ans = 0
    b = 0
    for a in A:
        if b==0:
            b = a
        else:
            if b*a<=0:
                ans += b
                b = a
            b = max(b,a)
    print(ans)