#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k, md = 0;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long tmp;
    long long sum = 0, prev_sum;
    for (long long i = 0; i < n; i++) {
      cin >> tmp;
      if (i == 0) {
        prev_sum = tmp;
        continue;
      }
      if (prev_sum * tmp > 0)
        prev_sum = max(tmp, prev_sum);
      else {
        sum += prev_sum;
        prev_sum = tmp;
      }
    }
    sum += prev_sum;
    cout << sum << "\n";
  }
  return 0;
}
