for i in range(int(input())):
    n = int(input())
    lis = [int(x) for x in input().split()]
    lis.append(0)
    p = lis[0]
    ans = 0
    for j in range(1, len(lis)):
        if(lis[j] >= 0 and p < 0) or (lis[j] <= 0 and p > 0):
            ans += p
            p = lis[j]
        elif lis[j] > p:
            p = lis[j]
    print(ans)
