for _ in range(int(input())):
    n = int(input())
    arr = [int(s) for s in input().split()]
    flag = True
    sum=0
    if arr[0]<0:
        flag = False
    maxi = arr[0]
    for i in range(1,len(arr)):
        if flag and arr[i]<0:
            flag = False
            sum+=maxi
            maxi = arr[i]
        elif not flag and arr[i]>0:
            flag = True
            sum+=maxi
            maxi = arr[i]
        else:
            maxi=max(arr[i],maxi)
    if arr[n-2]*arr[n-1] < 0:
        sum+=arr[n-1]
    else:
        sum+=maxi
    print(sum)
