for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    tempMinus = -10000000000
    tempPlus = 0
    ans = 0
    flag = 0
    if(arr[0]>0):
        flag = 1
    else:
        flag = 0
    for i in range(n):
        if(flag == 0):
            if(arr[i]>tempMinus):
                tempMinus = arr[i]
            if(i == n-1):
                ans += tempMinus
                break
            if(arr[i+1]> 0):
                ans += tempMinus
                flag = 1
                tempMinus = -10000000000
        elif(flag == 1):
            if(arr[i]>tempPlus):
                tempPlus = arr[i]
            if(i == n-1):
                ans += tempPlus
                break
            if(arr[i+1] < 0):
                ans += tempPlus
                flag = 0
                tempPlus = 0
    print(ans)

