import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
    n = int(input())
    a = list(map(int,input().split()))
    prev = a[0]
    s = 0
    m = prev
    for i in a[1:]:
        if i*prev > 0:
            m = max(m,i)
        else:
            s+=m
            m=i
        prev = i
    s+=m
    print(s)