for _ in range(int(input())):
    n = int(input())
    arr = [int(i) for i in input().split()]
    max_neg = max_pos = -(1e9 + 1)
    key = arr[0]
    ans = 0
    for i in arr[1:]:
        if i * key > 0:
            key = max(key, i)
        else:
            ans += key
            key = i
    print(ans + key)


