t = int(input())
while(t>0):
    l = int(input())
    arr = [int(x) for x in input().split(' ')]
    qi = 0
    q = [[arr[0]]]
    for i in range(1,l):
        if arr[i]*arr[i-1]>0:
            q[qi].append(arr[i])
        else:
            q.append([arr[i]])
            qi+=1
    s = 0
    for subsequence in q:
        s += max(subsequence)
    print(s)
    t-=1