T = int(input())
while T != 0:
    T = T - 1
    n = int(input())
    b = input().split(' ')
    a = [int(x) for x in b]
    v = a[0]
    s = 0
    for i in range(1, n):
        if a[i] > 0:
            if v > 0:
                v = max(v, a[i])
            else:
                s = s + v
                v = a[i]
        else:
            if v < 0:
                v = max(v, a[i])
            else:
                s = s + v
                v = a[i]
    s = s + v
    print(s)
    