for _ in range(int(input())):
    n = int(input())
    ar = list(map(int, input().split()))
    ans = []
    flag = 0
    num = 0
    for i in range(n):
        if ar[i] > 0 and flag == 0:
            num = max(ar[i], num)
        elif ar[i] < 0 and flag == 1:
            num = max(num, ar[i])
        else:
            ans.append(num)
            num = ar[i]
            flag += 1
            flag %= 2
    ans.append(num)
    print(sum(ans))