#include <bits/stdc++.h>
using namespace std;
unordered_set<int> int_set;
set<int, greater<int>> divisors;
bool srttt(const pair<int, int> &x, const pair<int, int> &y) {
  return (x.second < y.second);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    long long count = 0;
    vector<pair<long long, long long>> arr;
    for (long long i = 0; i < str.size(); i++) {
      if (str[i] == '+')
        count++;
      else
        count--;
      if (count < 0) arr.push_back(make_pair(count, i + 1));
    }
    if (arr.size() == 0) {
      cout << str.size() << "\n";
      continue;
    }
    sort(arr.begin(), arr.end(), srttt);
    long long ans = 0, px = 0;
    for (long long i = 0; i < arr.size(); i++) {
      long long m = abs(arr[i].first);
      if (m > px) {
        ans += (abs(arr[i].first) - px) * arr[i].second;
        px = abs(arr[i].first);
      }
    }
    ans += str.size();
    cout << ans << "\n";
  }
  return 0;
}
