#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  long long t;
  cin >> t;
  for (int num = 0; num < t; num++) {
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    long long SUM = 0;
    long long idx = 0;
    while (idx < N) {
      if (A[idx] > 0) {
        long long Max = A[idx];
        while (idx < N - 1 && A[idx + 1] > 0) {
          idx++;
          Max = max(Max, A[idx]);
        }
        SUM += Max;
      } else {
        long long Min = A[idx];
        while (idx < N - 1 && A[idx + 1] < 0) {
          idx++;
          Min = max(Min, A[idx]);
        }
        SUM += Min;
      }
      idx++;
    }
    cout << SUM << endl;
  }
}
