t = int(input())

for ts in range(t):
    l = int(input())
    a = [int(i) for i in input().split()]

    mode = a[0]/abs(a[0])
    su = 0
    m = a[0]
    for i in a:
        if(i*mode < 0):
            su+=m
            m = i
            mode*=-1
        else:
            m = max(m,i)
    su+=m
    print(su)
