MOD = 1000000007
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
ls = lambda :  list(input())
from collections import *
for _ in range(ii()):
    n=ii()
    a=il()
    m=a[0]
    c=[]
    for i in range(1,n):
        if(a[i-1]*a[i]>0):
            m=max(m,a[i])
        else:
            c.append(m)
            m=a[i]
    c.append(m)
    print(sum(c))