def check(x):
    if x < 0:
        return False
    return True


if __name__ == "__main__":
    T = int(input())
    while T:
        T -= 1
        N = int(input())
        A = list(map(int, input().split()))
        temp = A[:1]
        ans = []
        flag = check(A[0])
        for i in range(1, N):
            if check(A[i]) == flag:
                temp.append(A[i])
            else:
                ans.append(max(temp))
                temp = [A[i]]
                flag = not flag
        ans.append(max(temp))
        print(sum(ans))
