#include <bits/stdc++.h>
long long v[200000];
using namespace std;
int main() {
  int t, n, i, j;
  long long sum, c;
  cin >> t;
  for (int p = 0; p < t; p++) {
    cin >> n;
    for (i = 0; i < n; i++) cin >> v[i];
    sum = 0;
    for (int i = 0; i < n; i++) {
      c = v[i];
      for (j = i + 1; (v[j] < 0) == (v[j - 1] < 0) && j < n; j++) {
        c = max(c, v[j]);
      }
      sum += c;
      i = j - 1;
    }
    cout << sum << endl;
  }
  return 0;
}
