#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 + 5], mx = 0, mn = INT_MIN;
    for (int i = 0; i < n; i++) cin >> arr[i];
    if (arr[n - 1] > 0)
      arr[n] = -1;
    else
      arr[n] = 1;
    bool p = false, o = false;
    long long sum = 0;
    for (int i = 0; i <= n; i++) {
      if (arr[i] > 0) {
        if (o) {
          sum += mn;
          mn = INT_MIN;
        }
        p = true;
        o = false;
        mx = max(mx, arr[i]);
      } else {
        if (p) {
          sum += mx;
          mx = 0;
        }
        o = true;
        p = false;
        mn = max(mn, arr[i]);
      }
    }
    cout << sum << endl;
  }
  return 0;
}
