for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    s = 0
    f = 0
    v = []
    i = 0
    while i < n:
        if i < n and l[i] < 0:
            k = []
            while i < n and l[i] < 0:
                k.append(l[i])
                i += 1
            v.append(k)
        if i < n and l[i] > 0:
            k = []
            while i < n and l[i] > 0:
                k.append(l[i])
                i += 1
            v.append(k)
    for t in v:
        s += max(t)
    print(s)