#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n + 1];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long ans = 0;
    for (long long i = 0, j = 0; i < n; i = j) {
      long long x;
      (arr[i] > 0) ? x = 1 : x = 0;
      while (j < n) {
        long long y;
        (arr[j] > 0) ? y = 1 : y = 0;
        if (y == x) {
          j++;
        } else {
          break;
        }
      }
      long long maxE = arr[i];
      for (long long k = i; k < j; k++) {
        maxE = max(maxE, arr[k]);
      }
      ans += maxE;
    }
    cout << ans << endl;
  }
}
