#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair PII; #define fi first #define se second #define MP make_pair ll read() { ll v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();} while (48 <= c && c <= 57) v = v * 10 + c - 48, c = getchar(); return v * f; } int n; char ch[110000]; void Main() { memset(ch, 0, sizeof ch); scanf("%s", ch + 1); n = strlen(ch + 1); ll ans = 0; for (ll i = 1; i <= n; i++) { ll j = i; while (ch[j] == 'q') j++; ans += (j - i) * (j - i + 1) / 2; i = j; } printf("%I64d\n", ans); } int main() { ll T = read(); while (T--) Main(); }