#include #include #include #include #include #include #include #include using namespace std; char s[100006]; int main() { int t; scanf("%d",&t); while (t--) { scanf("%s",&s); long long cut=0; long long ans=0; for (int i=0;s[i];i++) { if (s[i]=='q') cut++; else { ans+=(cut-1)*cut/2+cut; cut=0; } } ans+=(cut-1)*cut/2+cut; printf("%I64d\n",ans); } }