#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    long long arr[n];
    bool flag = true;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[0] > 0)
        flag = true;
      else
        flag = false;
    }
    long long ans = -1e10, sum = 0;
    for (int i = 0; i < n; i++) {
      if ((arr[i] > 0 && flag == true) || (arr[i] < 0 && flag == false)) {
        sum += arr[i];
        if (flag == true)
          flag = false;
        else
          flag = true;
      } else {
        if (ans < sum) ans = sum;
        sum = arr[i];
      }
    }
    ans = max(sum, ans);
    cout << ans << endl;
  }
  return 0;
}
