#include <bits/stdc++.h>
using namespace std;
int main() {
  long T;
  cin >> T;
  while (T--) {
    long n;
    cin >> n;
    vector<long> v;
    for (long i = 0; i < n; i++) {
      long a;
      cin >> a;
      v.push_back(a);
    }
    long sign = v[0] > 0 ? 1 : -1;
    long max_num = v[0];
    long sum = 0;
    for (long i = 0; i < v.size(); i++) {
      if (sign * v[i] > 0) {
        max_num = max(max_num, v[i]);
      } else {
        sum += max_num;
        max_num = v[i];
        sign = v[i] > 0 ? 1 : -1;
      }
    }
    sum += max_num;
    cout << sum << endl;
  }
  return 0;
}
