#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int num;
    scanf("%d", &num);
    long long a[num];
    for (int i = 0; i < num; i++) scanf("%lld", &a[i]);
    long long sum = 0, f, r = a[0];
    if (a[0] > 0)
      f = 1;
    else
      f = -1;
    for (long long i = 1; i < num; i++) {
      if (f == 1 && a[i] > 0 && a[i - 1] > 0)
        r = max(r, a[i]);
      else if (f == 1 && a[i] < 0) {
        sum = sum + r;
        r = a[i];
        f = -1;
      } else if (f == -1 && a[i] < 0 && a[i - 1] < 0)
        r = max(r, a[i]);
      else if (f == -1 && a[i] > 0) {
        sum = sum + r;
        r = a[i];
        f = 1;
      }
    }
    cout << sum + r << endl;
  }
  return 0;
}
