n_s = int(input())

for x in range(n_s):
    n_sec = int(input())
    sec = list(map(int, input().split(" ")))
    max_len = 0
    max_sum = sec[0]    
    sum = sec[0]
    len = 1
    ant = sec[0]
    for i in range(1, n_sec): 
        if (ant * sec[i]) < 0:
            # Estoy en secuencia
            len += 1
            sum += sec[i]
            if len == max_len and sum > max_sum:
                # Dentro del mismo len encontre un mayor sum
                max_sum = sum
            if len > max_len:
                # tengo un nuevo max de len
                max_len = len
                max_sum = sum
        else:
            # Sali de secuencia
            sum = sec[i]
            len = 1
        #print("ant = ", ant, " sec[i] = ", sec[i], "max_len = ", max_len, " max_sum = ", max_sum)
        ant = sec[i]

    #print("max_len = ", max_len, " max_sum = ", max_sum)
    print(max_sum)
            