for _ in range(int(input())):
    n=int(input())
    T=[*map(int,input().split())]
    s=0
    i=0
    while(i<n):
        if(T[i]<0):
            m=T[i]
            while(i+1<n and T[i+1]<0):
                i += 1
                m = max(m, T[i])
        elif (T[i] > 0):
            m = T[i]
            while (i+1 < n and T[i+1] > 0):
                i += 1
                m = max(m, T[i])
        s += m
        i+=1
    print(s)