#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, n, k;
    cin >> n;
    long long arr[n];
    int cp = 0, cn = 0;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] > 0)
        cp++;
      else
        cn++;
    }
    long long max = -10000000000;
    int s;
    if (arr[0] > 0)
      s = 0;
    else
      s = 1;
    max = arr[0];
    long long sum = 0;
    for (i = 0; i < n; i++) {
      if (s == 0 && arr[i] < 0) {
        sum += max;
        max = arr[i];
        s = 1;
      } else if (s == 1 && arr[i] > 0) {
        sum += max;
        max = arr[i];
        s = 0;
      } else if (s == 0 && arr[i] > 0) {
        if (max < arr[i]) max = arr[i];
      } else {
        if (max < arr[i]) max = arr[i];
      }
    }
    sum += max;
    cout << sum << endl;
  }
  return 0;
}
