#include <bits/stdc++.h>
using namespace std;
long long int a_max(long long int arr[], long long int n) {
  long long int ans = arr[0];
  for (long long int i = 1; i < n; ++i) {
    if (ans < arr[i]) ans = arr[i];
  }
  return ans;
}
int main() {
  long long int tc;
  scanf("%lld", &tc);
  while (tc--) {
    long long int n;
    scanf("%lld", &n);
    long long int arr[n];
    for (long long int i = 0; i < n; ++i) scanf("%lld", arr + i);
    vector<long long int> v;
    v.push_back(0);
    for (long long int i = 0; i < n; ++i) {
      long long int pro = arr[v.back()] * arr[i];
      if (pro < 0) {
        v.push_back(i - 1);
        v.push_back(i);
      }
    }
    long long int answ = 0;
    v.push_back(n - 1);
    while (!v.empty()) {
      long long int r = v.back();
      v.pop_back();
      long long int l = v.back();
      v.pop_back();
      answ = a_max(arr + l, r - l + 1) + answ;
    }
    printf("%lld\n", answ);
  }
  return 0;
}
