#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int T;
  long long int N;
  cin >> T;
  for (long long int i = 1; i <= T; i++) {
    cin >> N;
    long long int array[N];
    int max = 0;
    long long sum = 0;
    for (long long int i = 0; i < N; i++) {
      cin >> array[i];
    }
    long long int flag;
    if (array[0] > 0) {
      flag = 1;
      max = array[0];
      sum = max;
    } else {
      flag = 0;
      max = array[0];
      sum = max;
    }
    for (long long int i = 1; i < N; i++) {
      if (array[i] > 0 && flag > 0) {
        if (max < array[i]) {
          sum = sum - max;
          max = array[i];
          sum = sum + max;
        }
      } else if (array[i] < 0 && flag > 0) {
        sum = sum + array[i];
        max = array[i];
        flag = 0;
      } else if (array[i] > 0 && flag == 0) {
        sum = sum + array[i];
        max = array[i];
        flag = 1;
      } else if (array[i] < 0 && flag == 0) {
        if (max < array[i]) {
          sum = sum - max;
          max = array[i];
          sum = sum + max;
        }
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
