#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
  a %= 1000000007;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long pref[s.length()];
    map<int, int> mp;
    int mx = 0;
    int cnt = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '+')
        cnt++;
      else
        cnt--;
      if (cnt < 0 && mp.find(cnt) == mp.end()) mp[cnt] = i + 1;
      mx = min(mx, cnt);
    }
    long long sum = 0;
    mx *= -1;
    for (int i = 0; i < mx; i++) {
      sum += mp[-(i + 1)];
    }
    sum += s.length();
    cout << sum << endl;
  }
}
