#include #include #include #include #include #include #define LL long long #define xx first #define yy second #define pii pair #define ls rt << 1 #define rs rt << 1 | 1 #define lson ls, l, m #define rson rs, m + 1, r using namespace std; const int N = 100010, INF = 0x3f3f3f3f; char s[N]; int main () { // freopen ("in.txt", "r", stdin); int T; cin >> T; while (T--) { scanf ("%s", s); int num = 0; LL res = 0; for (int i = 0; s[i]; i++) { if (s[i] == 'q') { num++; } else { res += 1LL * num * (num + 1) / 2; num = 0; } } res += 1LL * num * (num + 1) / 2; cout << res << endl; } }