#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, i;
    long long a[200005], max = -2e9, s = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
    a[n + 1] = -a[n];
    for (i = 1; i <= n; i++) {
      if (max < a[i])
        max = a[i];
      else
        max = max;
      if (a[i] * a[i + 1] < 0) {
        s += max;
        max = -2e9;
      }
    }
    printf("%lld\n", s);
  }
  return 0;
}
