#include #include #include #include #include using namespace std; const int MaxN = 1e5; int T; char s[MaxN + 5]; int main() { scanf("%d", &T); for (int i = 1; i <= T; i++) { scanf("%s", s); int len = strlen(s); long long cnt = 0, ans = 0; if (s[0] == 'q') cnt = 1; else cnt = 0; for (int j = 1; j < len; j++) { if (s[j] == 'q' && s[j - 1] == 'q') cnt++; if (s[j] != 'q' && s[j - 1] == 'q') ans += (cnt + 1) * cnt / 2; if (s[j] == 'q' && s[j - 1] != 'q') cnt = 1; } if (s[len - 1] == 'q') ans += (cnt + 1) * cnt / 2; printf("%I64d\n", ans); } }