#include <bits/stdc++.h>
using namespace std;
int sign(int i) { return i > 0; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long arr[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    long long sum = 0;
    long long maxn = arr[1];
    int i = 1;
    while (i <= n) {
      int j = i;
      maxn = arr[i];
      while (j <= n && sign(arr[i]) == sign(arr[j])) {
        maxn = max(maxn, arr[j]);
        j++;
      }
      sum += maxn;
      i = j;
    }
    cout << sum << endl;
  }
  return 0;
}
