#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);
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long sum = 0;
    int i = 0;
    while (i < n) {
      if (arr[i] > 0) {
        long long max = 0;
        while (arr[i] > 0) {
          if (arr[i] > max) {
            max = arr[i];
          }
          i++;
        }
        sum += max;
      } else {
        long long max = -1e9 - 1;
        while (arr[i] < 0) {
          if (arr[i] > max) {
            max = arr[i];
          }
          i++;
        }
        sum += max;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
