for _ in range(int(input())):
    input()
    a = [int(x) for x in input().split()]
    sum = 0
    sign = -1
    subsequence = []
    for i in range(len(a)):
        if i == 0:
            sign = a[i] > 0
            subsequence.append(a[i])
        else:
            if (sign and a[i] < 0) or (not sign and a[i] > 0):
                subsequence.append(a[i-1])
                sign = not sign

                sum += max(subsequence)
                subsequence.clear()
                subsequence.append(a[i])
    sum += max(subsequence)
    print(sum)



