#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    long long int sum = 0;
    long long int x = 0;
    int min = 0;
    int max = 0;
    if (arr[0] < 0)
      goto s1;
    else
      goto s2;
  s1:
    min = arr[x];
    while (arr[x] < 0 && x < n) {
      if (arr[x] > min) min = arr[x];
      x++;
      if (arr[x] > 0) {
        sum = sum + min;
        goto s2;
      }
    }
  s2:
    while (arr[x] > 0 && x < n) {
      max = 0;
      if (arr[x] > max) max = arr[x];
      x++;
      if (arr[x] < 0) {
        sum = sum + max;
        goto s1;
      }
    }
    if (arr[x - 1] > 0)
      sum = sum + max;
    else
      sum = sum + min;
    cout << sum << "\n";
  }
  return 0;
}
