for i in range(int(input())):
    c = int(input())
    f = [int(i) for i in input().split()]
    s = 0
    k = f[0]
    for j in range(1, c):
        if f[j] * f[j - 1] > 0:
            k = max(f[j], f[j - 1])
        else:
            s += k
            k = f[j]
    if f[c - 1] * f[c - 2] > 0:
        s += k
    else:
        s += f[c - 1]
    print(s)
