#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n, flagp = 0, flagn = 0, min, max;
    cin >> n;
    long long int arr[n];
    vector<long long int> v;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] < 0) {
        flagn = 1;
      } else {
        flagp = 1;
      }
    }
    int i = 0;
    while (i < n) {
      max = 0, min = 0;
      if (arr[i] > 0) {
        max = arr[i];
        i += 1;
        for (;;) {
          if (i >= n) break;
          if (arr[i] < 0)
            break;
          else {
            if (arr[i] > max) max = arr[i];
          }
          i += 1;
        }
        v.push_back(max);
      } else if (arr[i] < 0) {
        min = arr[i];
        i += 1;
        for (;;) {
          if (i >= n) break;
          if (arr[i] > 0)
            break;
          else {
            if (min < arr[i]) min = arr[i];
          }
          i += 1;
        }
        v.push_back(min);
      }
    }
    int s = v.size();
    long long int sum = 0;
    for (int i = 0; i < s; i++) {
      sum += v[i];
    }
    cout << sum;
    cout << endl;
  }
  return 0;
}
