t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    temp = a[0]
    ans = 0
    if a[0] > 0:
        now = 1
    else:
        now = -1
    for x in a[1:]:
        if now == 1:
            if x > 0:
                temp = max(temp,x)
            else:
                ans += temp
                temp = x
                now = -1
        else:
            if x < 0:
                temp = max(temp,x)
            else:
                ans += temp
                temp = x
                now = 1
    ans += temp
    print(ans)