#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i, f = 0, s = 0, c;
    cin >> n;
    vector<long long int> v(n);
    for (i = 0; i < n; i++) cin >> v[i];
    if (v[i] > 0)
      f = 1;
    else
      f = 0;
    i = 0;
    c = -1e18;
    while (i < n) {
      if (f) {
        if (v[i] > 0)
          c = max(c, v[i]), i++;
        else
          s += c, f = 0, c = -1e18;
      } else {
        if (v[i] < 0)
          c = max(c, v[i]), i++;
        else
          s += c, f = 1, c = -1e18;
      }
    }
    cout << s + c << endl;
  }
}
