#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int T, n;
  cin >> T;
  while (T--) {
    stack<long long int> S;
    cin >> n;
    long long int *a = new long long int[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long int prev_sign = 0, sign = 0, ns = 0;
    S.push(a[0]);
    if (a[0] > 0) prev_sign = 1;
    if (a[0] < 0) prev_sign = -1;
    for (long long int i = 1; i < n; i++) {
      if (a[i] > 0) sign = 1;
      if (a[i] < 0) sign = -1;
      if (sign != prev_sign) {
        S.push(a[i]);
        ns++;
        prev_sign = sign;
        continue;
      } else {
        if (S.top() < a[i]) {
          S.pop();
          S.push(a[i]);
          prev_sign = sign;
          continue;
        }
      }
    }
    long long int ans = 0;
    for (long long int i = 0; i <= ns; i++) {
      ans = ans + S.top();
      S.pop();
    }
    cout << ans << endl;
  }
}
