def main():
    n_s = int(input())

    for x in range(n_s):
        int(input())
        sec = list(map(int, input().split(" ")))
        ant = sec[0]
        max = ant
        sum = 0
        for n in sec[1:]: 
            if (ant * n) > 0:
                # No he cambiado de signo
                if n > max:
                    max = n
            else:
                sum += max
                max = n
            #print("ant = ", ant, " sec[i] = ", n, " sum = ", sum)
            ant = n

        #print("max_len = ", max_len, " max_sum = ", max_sum)
        print(sum + max)
            
main()