#include #include #include #include using namespace std; #define LL long long const LL M = 1000000007; char s[10000]; LL sum[30]; int t; int len; LL ans; LL ExGcd(LL a, LL b, LL& x, LL& y) { if(b == 0) { x = 1; y = 0; return 0; } else { LL x1, y1; LL d = ExGcd(b, a%b, x1, y1); x = y1; y = x1-a/b*y1; return d; } } void Nex(LL k) { for(LL i = 1; i <= k; i++) { LL x, y, d; d = ExGcd(M, i, x, y); //printf("%22I64d\n", y); while(y < 0) y += M; y = (y+M)%M; ans *= y; ans %= M; } } int main() { //freopen("test.in", "r", stdin); scanf("%d", &t); for(int tm = 1; tm <= t; tm++) { memset(s, 0, sizeof(s)); memset(sum, 0, sizeof(sum)); scanf("%s", s); len = strlen(s); ans = 1; for(int i = 0; i < len; i++) sum[s[i]-'a']++; //printf("%5d\n", len); /* for(int i = 0; i < 26; i++) { if(sum[i]) printf("%5d%5I64d\n", i, sum[i]); } */ int p = 0; for(int i = 0; i < 26; i++) if(sum[i]%2 == 1) p++; if(p && len%2 == 0) printf("0\n"); else if(p > 1 && len%2 == 1) printf("0\n"); else { for(LL i = 1; i <= len/2; i++) { ans *= i; ans %= M; //printf("%I64d\n", ans); } for(LL i = 0; i < 26; i++) { if(sum[i]) { Nex(sum[i]/2); ans %= M; } } printf("%I64d\n", ans); } } }