#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1000000000;
int main() {
  long t;
  cin >> t;
  while (t--) {
    long n;
    cin >> n;
    std::vector<long int> v(n, 0);
    for (long i = 0; i < n; i++) {
      cin >> v[i];
    }
    long long int sum = 0, i = 0, j = 0, maxp = 0, maxn = -inf;
    while (i < n && j < n) {
      maxp = 0;
      maxn = -inf;
      while (v[i] < 0 && i < n) {
        i++;
      }
      while (v[i] >= 0 && i < n) {
        if (maxp < v[i]) maxp = v[i];
        i++;
      }
      while (v[j] >= 0 && j < n) {
        j++;
      }
      while (v[j] < 0 && j < n) {
        if (maxn < v[j]) maxn = v[j];
        j++;
      }
      if (maxn != inf) {
        sum += maxp + maxn;
      }
    }
    cout << sum << endl;
  }
}
