#include <bits/stdc++.h>
using namespace std;
int a[200008], n, t;
int main() {
  scanf("%d", &t);
  for (int i = 1; i <= t; ++i) {
    scanf("%d", &n);
    int duong = 0;
    int am = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      if (a[i] > 0)
        ++duong;
      else
        ++am;
    }
    long long ans = 0;
    if (duong == 0 || am == 0) {
      ans = -10000000000000;
      for (int i = 1; i <= n; ++i) ans = max(ans, (long long)a[i]);
    } else {
      a[n + 1] = -a[n];
      a[0] = a[1];
      int mx = INT_MIN;
      for (int i = 1; i <= n + 1; ++i) {
        if ((a[i] > 0 && a[i - 1] > 0) || (a[i] < 0 && a[i - 1] < 0)) {
          mx = max(mx, a[i]);
        } else {
          ans += mx;
          mx = a[i];
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
