inf = 10**9+7
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    if a[0] > 0:
        neg_f = False
    else:
        neg_f = True
    tmp = a[0]
    for num in a:
        if (neg_f and num > 0) or ((not neg_f) and num < 0):
            ans += tmp
            neg_f = not neg_f
            tmp = -inf
        tmp = max(num, tmp)
    ans += tmp
    print(ans)