#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      arr[i] = temp;
    }
    int mal = 1;
    long long int res = arr[0];
    for (int i = 0; i < n; i++) {
      int pre = arr[i];
      int len = 1;
      long long int sum = arr[i];
      for (int j = i + 1; j < n; j++) {
        if (arr[j] * pre < 0) {
          len++;
          pre = arr[j];
          sum += arr[j];
        }
      }
      if (len > mal) {
        mal = len;
        res = sum;
      } else if (len == mal) {
        res = max(res, sum);
      }
    }
    cout << res << endl;
  }
  return 0;
}
