t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = [[a[0]]]
    for i in range(1, n):
        if a[i] > 0:
            if a[i - 1] > 0:
                b[-1].append(a[i])
            else:
                b.append([a[i]])
        else:
            if a[i - 1] < 0:
                b[-1].append(a[i])
            else:
                b.append([a[i]])
    s = 0
    for i in b:
       s += max(i)
    print(s)