t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))[:n]
    S = 0
    m = a[0]
    a.append(-a[-1])
    for x in a[1:]:
        if x*m > 0:
            m = max(x,m)
        else:
            S += m
            m = x
    print(S)