#include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 0x7fffffff #define mod 10000 #define met(a,b) memset(a,b,sizeof a) typedef long long ll; using namespace std; const int N = 100; const int M = 100000; const int INF = 0x3f3f3f3f; int x; char s[100002]; long long int a[1000]; int main() { long long int sum = 0; int t; scanf("%d", &t); while(t--) { scanf("%s", s); int len = strlen(s); long long int cnt = 0; sum = 0; for(int i = 0; i < len; i++) { if(s[i] == 'q') { cnt++; }else if(cnt > 0){ sum += cnt*(cnt+1)/2; cnt = 0; } } if(cnt > 0) sum += cnt*(cnt+1)/2; printf("%lld\n", sum); } }