from itertools import groupby
t = int(input())
for _ in range(0,t):
    n = int(input())
    aa = [int(i) for i in input().split()]
    ss = 0
    ans = [[]]
    if aa[0] > 0:
        k = True
    else:
        k = False
    for i in range(0,n):
        if aa[i]>0 and k:
            ans[-1].append(aa[i])
        elif aa[i] < 0 and not k:
            ans[-1].append(aa[i])
        elif aa[i] > 0 and not k:
            k = True
            ans.append([])
            ans[-1].append(aa[i])
        elif aa[i] < 0 and k:
            k = False
            ans.append([])
            ans[-1].append(aa[i])
    for i in ans:
        ss += max(i)
    print(ss)
