import io, os
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
R = lambda : map(int, input().split())
def che(x) :
    if x > 0 :
        return 1
    if x < 0 :
        return -1
for _ in range(int(input())) :
    n = int(input())
    a = list(R())
    dp, pre, siz = 0, 0, 0
    now = che(a[0])
    for i in a :
        if che(i) == now :
            dp += i
            siz += 1
            pre = i
            now = -now
        elif i > pre:
            dp -= pre
            pre = i
            dp += pre
    print(dp)

