for _ in range(int(input())):
    n = int(input())
    a = [int(i) for i in input().split()]

    s = 0
    cur_max = a[0]
    for i in range(1, len(a)):
        if(a[i]*a[i-1]<0):
            s += cur_max
            cur_max = a[i]
        else:
            cur_max = max(cur_max, a[i])
    print(s+cur_max)