t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    if arr[0]<0:
        flag = -1
    else:
        flag = 1

    brr = []
    i = 0
    while i<n:
        check = []
        if flag == -1:
            while i<n and arr[i]<0:
                check.append(arr[i])
                i+=1
            brr.append(max(check))
            flag = 1
        else:
            while i<n and arr[i]>=0:
                check.append(arr[i])
                i+=1
            brr.append(max(check))
            flag = -1
    print(sum(brr))