#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int sz = s.size();
    int dp[sz];
    for (int i = 0; i < sz; i++) dp[i] = 0;
    if (s[0] == '+')
      dp[0] = 1;
    else
      dp[0] = -1;
    for (int i = 1; i < sz; i++) {
      dp[i] = dp[i - 1] + (s[i] == '+' ? 1 : -1);
    }
    long long int sum = 0;
    int lo = 0, idx = 0;
    while (lo < sz) {
      if (dp[lo] < 0 && ((idx + dp[lo]) < 0)) {
        sum += (lo + 1);
        idx++;
      }
      lo++;
    }
    sum += (lo);
    cout << sum << "\n";
  }
}
