#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n), state(n), ans;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] > 0) state[i] = 1;
    }
    bool flag = 0;
    if (arr[0] > 0) flag = 1;
    long long maximum = LLONG_MIN, sum = 0;
    for (int i = 1; i < n;) {
      maximum = arr[i - 1];
      if (state[i] == state[i - 1]) {
        while (i < n && state[i] == state[i - 1]) {
          maximum = max(maximum, arr[i]);
          i++;
        }
        sum += maximum;
        i++;
      } else {
        i++;
        sum += maximum;
      }
    }
    if (n >= 2 && state[n - 2] != state[n - 1]) sum += arr[n - 1];
    cout << sum << endl;
  }
  return 0;
}
