# ----------------------------
# Escape Sequences Characters
# \b => Back Space
# \newline => Escape New Line + \
# \\ => Escape Back Slash
# \' => Escape Single Quotes
# \" => Escape Double Quotes
# \n => Line Feed
# \r => Carriage Return
# \t => Horizontal Tab
# \xhh => Character Hex Value
# ----------------------------
# -- Strings Methods --
# strip() rstrip() lstrip()
# title() istitle() captilaze upper lower
# zfill
# split() rsp..
# ---------------------
# list it's look like array == []
# list is order & indexed & mutable & ununiqe
# tuple is order & indexed & unmutable & ununiqe == ()
# set is unorder & unindexed & unmutable & uniqe =={}
# -- Dictionary --
# [1] Dict Items Are Enclosed in Curly Braces
# [2] Dict Items Are Contains Key : Value
# [3] Dict Key Need To Be Immutable => (Number, String, Tuple) List Not Allowed
# [4] Dict Value Can Have Any Data Types
# [5] Dict Key Need To Be Unique
# [6] Dict Is Not Ordered You Access Its Element With Key
# ----------------------------
alph = "abcdefghijklmnopqrstuvwxyz"




# test your function

for _ in range(int(input())):
  n= int( input() )
  arr = (input()).split()
  a=[]
  for i in range(len(arr)):
    a.append(int(arr[i]))
  #print(a)
  con = a[0]
  temp=a[0]
  for i in range(n-1):
    if( ( (a[i]> 0 and a[i+1]>0) or (a[i]<0 and a[i+1]<0) ) and a[i+1]>temp):
      con=con+a[i+1]-temp
      temp=a[i+1]
      #print(con)
      #print(a[i])
    elif( (a[i]>0 and a[i+1]<0) or (a[i]<0 and a[i+1]>0) ):
      con=con+a[i+1]
      temp=a[i+1]

  print(con)

