t = int(input())
for j in range(t):
    n = int(input())
    arr = [int(i) for i in input().split()]
    sarr = []
    total = 0
    for i in arr:
        if(i>0):
            sarr.append(1)
        else:
            sarr.append(-1)
    #print(sarr)
    i = 0
    while(i<n):
        curr = arr[i]
        j = i
        while(j<n and sarr[i]==sarr[j]):
            curr = max(curr, arr[j])
            j += 1
        total += curr
        i = j
    print(total)
