#include <bits/stdc++.h>
const int mod = 1e9 + 7, MAX = 1e6 + 5;
const long long inf = 1e18 + 5;
const double pi = 3.14159265358979323846;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long* A = new long long[n];
    for (long long i = 0; i < n; i++) cin >> A[i];
    long long answer = 0;
    long long i = 0;
    while (i < n) {
      long long h = -1 * inf;
      if (A[i] < 0) {
        while (i < n && A[i] < 0) {
          h = max(h, A[i]);
          i++;
        }
        answer += h;
      } else {
        while (i < n && A[i] > 0) {
          h = max(h, A[i]);
          i++;
        }
        answer += h;
      }
    }
    cout << answer << "\n";
  }
  return 0;
}
