for q in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    now = a[0]
    sum = 0
    for i in range(1, n):
        if a[i] * a[i - 1] > 0:
            now = max(now, a[i])
        else:
            sum += now
            now = a[i]
    sum += now
    print(sum)