#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    int n;
    cin >> n;
    long long int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int index = 0;
    int max = INT_MIN;
    int min = INT_MAX;
    if (arr[0] >= 0) {
      max = arr[0];
      for (int i = 0; i < n; i++) {
        if (arr[i] < 0) {
          break;
        } else if (arr[i] >= max) {
          max = arr[i];
          index = i;
        }
      }
    } else {
      max = arr[0];
      for (int i = 0; i < n; i++) {
        if (arr[i] > 0) {
          break;
        } else if (arr[i] >= max) {
          max = arr[i];
          index = i;
        }
      }
    }
    long long int newArr[n];
    newArr[0] = arr[index];
    int count = 1;
    for (int i = index; i < n; i++) {
      if ((arr[i] >= 0 && newArr[count - 1] <= 0) ||
          (arr[i] < 0 && newArr[count - 1] > 0)) {
        if (arr[i] >= 0) {
          max = arr[i];
          for (int k = i; k < n; k++) {
            if (arr[k] < 0) {
              break;
            } else if (arr[k] >= max) {
              max = arr[k];
              index = k;
            }
          }
        } else {
          max = arr[i];
          for (int k = i; k < n; k++) {
            if (arr[k] > 0) {
              break;
            } else if (arr[k] >= max) {
              max = arr[k];
              index = k;
            }
          }
        }
        newArr[count] = arr[i];
        count++;
      }
    }
    long long int sum = 0;
    for (int i = 0; i < count; i++) {
      sum = sum + newArr[i];
    }
    cout << sum << endl;
  }
}
