#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    long long sum = 0;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long i = 0;
    while (i < n) {
      long long num = a[i];
      i++;
      if (i < n) {
        while ((num * a[i]) > 0) {
          num = max(num, a[i]);
          i++;
        }
      }
      sum += num;
    }
    cout << sum << endl;
  }
  return 0;
}
