for _ in range(int(input())):
    n = int(input())
    *a, = map(int, input().split())
    ans = 0
    cur =  a[0]
    for i in range(1, n):
        if cur * a[i] < 0:
            ans += cur
            cur = a[i]
        else:
            cur = max(cur, a[i])
    ans += cur
    print(ans)
        