#include <bits/stdc++.h>
using namespace std;
char str[(int)1e6 + 500];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", str);
    long long res = 0;
    int cur = 0;
    set<int> st;
    for (int i = 0; str[i]; i++) {
      if (str[i] == '-')
        cur--;
      else
        cur++;
      if (cur < 0 && st.find(cur) == st.end()) {
        st.insert(cur);
        res += i + 1;
      }
    }
    printf("%lld\n", res + (long long)strlen(str));
  }
}
