#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;
    for (long long i = 0; i < n; i++) {
      long long value;
      cin >> value;
      arr.push_back(value);
    }
    long long sum = 0, neg = 0, pos = 0;
    for (long long i = 0; i < n;) {
      long long flag = 0;
      if (arr[i] < 0) {
        if (neg == 0) {
          neg = arr[i];
          i++;
          flag = 1;
        }
        while (arr[i] < 0) {
          if (neg < arr[i]) neg = arr[i];
          i++;
          flag = 1;
        }
        sum = sum + neg;
        neg = 0;
      } else {
        if (pos == 0) {
          pos = arr[i];
          i++;
          flag = 1;
        }
        while (arr[i] > 0) {
          if (pos < arr[i]) pos = arr[i];
          i++;
          flag = 1;
        }
        sum = sum + pos;
        pos = 0;
      }
      if (flag == 0) i++;
    }
    cout << sum << endl;
  }
  return 0;
}
