for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    s = 0
    current_sign = -l[0]/abs(l[0])
    current_max = l[0]
    for i in l:
        if i*current_sign<0:
            current_sign = -current_sign
            current_max = i
            s += i
        if i>current_max:
            s += (i-current_max)
            current_max = i

    print(s)



