for _ in range(int(input())):
    n = int(input())
    # m, d, n = list(map(int, input().split())) 
    arr = list(map(int, input().split()))
    # arr = list(input())
    temp = []
    ans = 0
    if arr[0] >= 0:
        flag = 1
    else:
        flag = 0
    for i in range(n):
        if arr[i] >= 0:
            if flag == 1:
                temp.append(arr[i])
            else:
                # ans.append(temp)
                ans += (max(temp))
                temp = []
                temp.append(arr[i])
                flag = 1
        else:
            if flag == 0:
                temp.append(arr[i])
            else:
                # ans.append(temp)
                ans += (max(temp))
                temp = []
                temp.append(arr[i])
                flag = 0
    if flag == 1:
        ans += max(temp)
    else:
        ans += max(temp)
    print(ans)