for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))

    if arr[0] < 0:
        f = True
    else:
        f = False
    ans = 0
    m = -10 ** 10
    for x in arr:

        if f:
            if x < 0:
                m = max(m, x)
            else:
                f = False
                ans += m
                m = -10 ** 10
                m = max(m, x)
        else:
            if x >= 0:
                m = max(m, x)
            else:
                f = True

                ans += m
                m = -10 ** 10
                m = max(m, x)
    print(ans+m)
