#include <bits/stdc++.h>
int t, n;
int a[1145141];
int abs(int x) { return x < 0 ? -x : x; }
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    long long ans = 0, lst = a[1];
    for (int i = 1; a[i]; ++i)
      if (a[i] / abs(a[i]) == lst / abs(lst))
        if (a[i] > lst)
          lst = a[i];
        else
          ;
      else
        ans += lst, lst = a[i];
    printf("%lld\n", ans + lst);
  }
}
