t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    res = []
    res.append(a[0])
    
    for i in range(1, n):
        if a[i] > 0 and a[i-1] < 0:
            res.append(a[i])
        elif a[i] > 0 and a[i-1] > 0:
            res[-1] = max(res[-1], a[i])
        elif a[i] < 0 and a[i-1] > 0:
            res.append(a[i])
        elif a[i] < 0 and a[i-1] < 0:
            res[-1] = max(res[-1], a[i])
    print(sum(res))