#include <bits/stdc++.h>
using namespace std;
int inf = 0x3f3f3f3f;
long long linf = 0x3f3f3f3f3f3f3f3f;
int popcnt(int a) { return __builtin_popcount(a); }
int popcnt(long long a) { return __builtin_popcountll(a); }
int msb(int a) { return 32 - __builtin_clz(a); }
int msb(long long a) { return 64 - __builtin_clzll(a); }
int lsb(int a) { return __builtin_ctz(a); }
int lsb(long long a) { return __builtin_ctzll(a); }
template <typename T, typename U>
T ipow(T a, U e) {
  T b = 1;
  while (e) {
    if (e & 1) b *= a;
    a *= a;
    e >>= 1;
  }
  return b;
}
template <typename T>
void tobin(T v, int len = sizeof(T) * CHAR_BIT) {
  while (--len >= 0) putchar("10"[!(v & (1 << len))]);
}
template <class InputIterator>
void prnt(InputIterator first, InputIterator last, char delim = ' ') {
  for (auto it = first; it != last; it++) cout << *it << delim;
  puts("");
}
template <typename T>
struct range_it : std::iterator<random_access_iterator_tag, T> {
  T v;
  range_it(T _v) : v(_v) {}
  operator T&() { return v; }
  T operator*() const { return v; }
};
template <typename T>
struct range {
  T b, e, s;
  range(T _e) : b(0), e(_e), s(1){};
  range(T _b, T _e, T _s = 1) : b(_b), e(_e), s(_s) {}
  range_it<T> begin() { return b; };
  range_it<T> end() { return e; }
  range_it<T> rbegin() { return e - 1; };
  range_it<T> rend() { return b - 1; }
};
template <typename T>
struct range<T> lr(T b, T e, T s = 1) {
  return range<T>(b + 1, e, s);
} template <typename T>
struct range<T> lR(T b, T e, T s = 1) {
  return range<T>(b + 1, e + 1, s);
} template <typename T>
struct range<T> Lr(T b, T e, T s = 1) {
  return range<T>(b, e, s);
} template <typename T>
struct range<T> LR(T b, T e, T s = 1) {
  return range<T>(b, e + 1, s);
} template <typename T>
struct range<T> Lr(T e) {
  return range<T>(e);
} template <typename T>
struct range<T> LR(T e) {
  return range<T>(e + 1);
} int main() {
  int qq;
  scanf("%d", &qq);
  while (qq--) {
    string s;
    cin >> s;
    vector<int> a((int)s.size() + 1);
    int n = (int)s.size();
    a[0] = s[0] == '+' ? 1 : -1;
    for (int i = 1; i < (int)s.size(); i++) {
      a[i] = a[i - 1] + (s[i] == '+' ? 1 : -1);
    }
    int mn = 0;
    for (int i = 0; i < n; i++) {
      a[i] = mn = min(mn, a[i]);
    }
    int cr = -a[n - 1] + 1;
    long long sm = 0;
    for (int i = 0; i < n; i++) {
      int t = i > 0 ? (a[i] < a[i - 1]) : a[i] < 0;
      sm += cr;
      cr -= t;
    }
    cout << sm << endl;
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: 
    
    
    res = 0  
    for init = 0 to inf  
        cur = init  
        ok = true  
        for i = 1 to |s|  
            res = res + 1  
            if s[i] == '+'  
                cur = cur + 1  
            else  
                cur = cur - 1  
            if cur < 0  
                ok = false  
                break  
        if ok  
            break  
    

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.

You have to calculate the value of the res after the process ends.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only lines of each test case contains string s (1 ≤ |s| ≤ 10^6) consisting only of characters + and -.

It's guaranteed that sum of |s| over all test cases doesn't exceed 10^6.

Output

For each test case print one integer — the value of the res after the process ends.

Example

Input


3
--+-
---
++--+-


Output


7
9
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int inf = 0x3f3f3f3f;
long long linf = 0x3f3f3f3f3f3f3f3f;
int popcnt(int a) { return __builtin_popcount(a); }
int popcnt(long long a) { return __builtin_popcountll(a); }
int msb(int a) { return 32 - __builtin_clz(a); }
int msb(long long a) { return 64 - __builtin_clzll(a); }
int lsb(int a) { return __builtin_ctz(a); }
int lsb(long long a) { return __builtin_ctzll(a); }
template <typename T, typename U>
T ipow(T a, U e) {
  T b = 1;
  while (e) {
    if (e & 1) b *= a;
    a *= a;
    e >>= 1;
  }
  return b;
}
template <typename T>
void tobin(T v, int len = sizeof(T) * CHAR_BIT) {
  while (--len >= 0) putchar("10"[!(v & (1 << len))]);
}
template <class InputIterator>
void prnt(InputIterator first, InputIterator last, char delim = ' ') {
  for (auto it = first; it != last; it++) cout << *it << delim;
  puts("");
}
template <typename T>
struct range_it : std::iterator<random_access_iterator_tag, T> {
  T v;
  range_it(T _v) : v(_v) {}
  operator T&() { return v; }
  T operator*() const { return v; }
};
template <typename T>
struct range {
  T b, e, s;
  range(T _e) : b(0), e(_e), s(1){};
  range(T _b, T _e, T _s = 1) : b(_b), e(_e), s(_s) {}
  range_it<T> begin() { return b; };
  range_it<T> end() { return e; }
  range_it<T> rbegin() { return e - 1; };
  range_it<T> rend() { return b - 1; }
};
template <typename T>
struct range<T> lr(T b, T e, T s = 1) {
  return range<T>(b + 1, e, s);
} template <typename T>
struct range<T> lR(T b, T e, T s = 1) {
  return range<T>(b + 1, e + 1, s);
} template <typename T>
struct range<T> Lr(T b, T e, T s = 1) {
  return range<T>(b, e, s);
} template <typename T>
struct range<T> LR(T b, T e, T s = 1) {
  return range<T>(b, e + 1, s);
} template <typename T>
struct range<T> Lr(T e) {
  return range<T>(e);
} template <typename T>
struct range<T> LR(T e) {
  return range<T>(e + 1);
} int main() {
  int qq;
  scanf("%d", &qq);
  while (qq--) {
    string s;
    cin >> s;
    vector<int> a((int)s.size() + 1);
    int n = (int)s.size();
    a[0] = s[0] == '+' ? 1 : -1;
    for (int i = 1; i < (int)s.size(); i++) {
      a[i] = a[i - 1] + (s[i] == '+' ? 1 : -1);
    }
    int mn = 0;
    for (int i = 0; i < n; i++) {
      a[i] = mn = min(mn, a[i]);
    }
    int cr = -a[n - 1] + 1;
    long long sm = 0;
    for (int i = 0; i < n; i++) {
      int t = i > 0 ? (a[i] < a[i - 1]) : a[i] < 0;
      sm += cr;
      cr -= t;
    }
    cout << sm << endl;
  }
  return 0;
}

```