#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, i;
    cin >> n;
    long long j;
    long long p = 0, q = -inf, ans = 0, flag;
    cin >> j;
    if (j > 0) {
      p = j;
      flag = 0;
    } else {
      q = j;
      flag = 1;
    }
    i = 1;
    while (i < n) {
      cin >> j;
      if (flag == 0) {
        if (j > 0) {
          p = max(p, j);
        } else {
          q = j;
          ans += p;
          flag = 1;
          p = 0;
        }
      } else {
        if (j < 0) {
          q = max(q, j);
        } else {
          p = j;
          ans += q;
          flag = 0;
          q = -inf;
        }
      }
      i++;
      if (i == n) break;
    }
    if (flag == 1)
      ans += q;
    else
      ans += p;
    cout << ans << endl;
  }
  return 0;
}
