
t = int(input())

for loop in range(t):

    n = int(input())

    a = list(map(int,input().split()))

    if a[0] > 0:
        state = 0
    else:
        state = 1

    nmax = float("-inf")
    ans = 0
    
    for i in range(n):

        if state == 0:
            if a[i] > 0:
                nmax = max(nmax, a[i])
            else:
                ans += nmax
                state = 1
                nmax = a[i]
        else:
            if a[i] < 0:
                nmax = max(nmax , a[i])
            else:
                ans += nmax
                state = 0
                nmax = a[i]

    ans += nmax
    print (ans)
