for _ in range(int(input())):
    n = int(input())
    a = input().split()
    a = [int(i) for i in a]
    turn = 0
    sum = 0
    for i in range(n-1):
        if (a[i+1]<0 and a[i]>0) or (a[i+1]>0 and a[i]<0):
            sum+=max(a[turn:i+1])
            turn = i+1
    sum+=max(a[turn:])
    if turn>0:
        print(sum)
    else:
        print(max(a))