<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

537. Divisibility
Time limit per test: 1.5 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

Inspired by Stephen Graham, the King of Berland started to study algorithms on strings. He was working days and nights, having a feeling that the full potential in this area is still to be unlocked. And he was right!

One day, all the sudden, he made a huge breakthrough by discovering the fact that strings can be magically transformed into integer numbers. It was so simple! You just have to map different letters to different digits and be careful enough not to introduce any leading zeroes.

Here is what he wrote in his textbook about the string 'lalala':
it can be transformed to an 282828 by mapping 'l' to 2, and 'a' to 8
it can also be transformed to 909090 by mapping 'l' to 9, and 'a' to 0
a couple of examples of invalid transformations are 050505 (the resulting number has a leading zero), 333333 (different letters are mapped to the same digit), 123456 (no mapping to the original letters at all)


But then things started to become more interesting. Obviously, it was known from very beginning that a single string can potentially be mapped to a variety of different integer numbers. But the King couldn't even imagine that all numbers produced by the same string pattern might have common properties!

For example, every single number that can be produced from string 'lalala' is always divisible by 259, irrespective of the letter-to-digit mapping you choose. Fascinating!

So the King ended up with the following problem. For any given string, he wanted to come up with an algorithm to calculate the set of its divisors. A number is called a divisor of the given string if all positive integers, that could possibly be produced from the given string, are divisible by it.

As usual, the King desperately wants you to help him, so stop thinking and start acting!

Input
Input consists of multiple test cases. The first line of input contains an integer number n (1 ≤ n ≤ 100) — the number of test cases.

Each of the next n lines contains a string pattern to be processed. Each pattern consists of lowercase Latin letters. Its length will always be between 1 and 14 characters, and the number of different characters in the pattern will never exceed 10 to ensure correct mapping to digits 0-9.

Output
For every test case print a line with the corresponding test case number and the calculated list of divisors. Output positive divisors in an increasing order, separating them with a single space. Format your output according to the example given in the sample test case.

Example(s)
sample input
sample output
5
cat
bbb
ololo
lala
icpcicpc
Case 1: 1
Case 2: 1 3 37 111
Case 3: 1
Case 4: 1 101
Case 5: 1 73 137 10001

<|response|>
1. Abridged Problem Statement  
You are given a lowercase string s of length up to 14 and containing at most 10 distinct letters.  We consider all ways to map each distinct letter to a distinct digit (0–9), with the restriction that the first letter of s cannot map to 0.  Each mapping φ produces an integer N(φ).  Find all positive integers d such that N(φ) is divisible by d for every valid mapping φ.  Output these divisors in increasing order.

2. Key Observations  
- Any mapped number can be written as  
    N(φ) = ∑_{c in letters} mask[c] * φ(c)  
  where mask[c] = ∑_{i: s[i]=c} 10^{(n−1−i)}.  
- If you take two mappings φ and ψ that only differ by swapping the digit assigned to letters x and y, then  
    N(φ) − N(ψ) = (φ(x)−φ(y))·(mask[x] + mask[y]).  
- Since φ(x) and φ(y) can differ by any integer from −9 to +9, the greatest common divisor G of all N(φ) must divide every (mask[x] + mask[y]) for x≠y.  
- Therefore,  
    G = gcd({ mask[x] + mask[y] | x,y distinct letters }).  
- Special case: if the string has only one distinct letter c, then N(φ) = mask[c]·d for d=1…9, so G = mask[c].

3. Full Solution Approach  
1. Read the string s and compute n = length(s).  
2. Build a map mask[c]:  
     initialize place = 1  
     for i from n−1 down to 0:  
       mask[s[i]] += place  
       place *= 10  
3. Collect all the distinct letters into a vector L.  
4. Compute G:  
     if |L|=1:  
       G = mask[L[0]]  
     else:  
       G = 0  
       for each unordered pair (x,y) in L:  
         G = gcd(G, mask[x] + mask[y])  
5. Factorize G by trial‐division up to sqrt(G):  
     for p = 2; p*p ≤ G; ++p (skip even p>2):  
       if p divides G, extract exponent e, store (p,e), divide G by p^e  
     if remainder > 1, it is a prime factor.  
6. Generate all divisors from the prime factorization by a standard “multiply‐out” method.  
7. Sort the divisors and print them.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

// Compute GCD of two 64-bit integers
int64 gcd64(int64 a, int64 b) {
    while (b) {
        int64 t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    for(int tc = 1; tc <= T; tc++){
        string s;
        cin >> s;
        int n = s.size();

        // Step 1–2: compute mask for each letter
        // mask[c] = sum of 10^(position) over all positions where s[pos] == c
        unordered_map<char,int64> mask;
        int64 place = 1;
        for(int i = n-1; i >= 0; i--){
            mask[s[i]] += place;
            place *= 10;
        }

        // Collect distinct letters
        vector<pair<char,int64>> letters;
        letters.reserve(mask.size());
        for(auto &kv : mask){
            letters.push_back(kv);
        }

        // Step 4: compute G
        int m = letters.size();
        int64 G = 0;
        if(m == 1){
            // Only one letter in the string
            G = letters[0].second;
        } else {
            // G = gcd of mask[x] + mask[y] over all pairs
            for(int i = 0; i < m; i++){
                for(int j = i+1; j < m; j++){
                    int64 sumw = letters[i].second + letters[j].second;
                    G = gcd64(G, sumw);
                }
            }
        }

        // Step 5: factorize G by trial division
        int64 tmp = G;
        vector<pair<int64,int>> factors;
        // check factor 2
        if(tmp % 2 == 0){
            int cnt = 0;
            while(tmp % 2 == 0){
                tmp /= 2;
                cnt++;
            }
            factors.emplace_back(2, cnt);
        }
        // check odd candidates
        for(int64 p = 3; p * p <= tmp; p += 2){
            if(tmp % p == 0){
                int cnt = 0;
                while(tmp % p == 0){
                    tmp /= p;
                    cnt++;
                }
                factors.emplace_back(p, cnt);
            }
        }
        if(tmp > 1){
            factors.emplace_back(tmp, 1);
        }

        // Step 6: generate all divisors
        vector<int64> divisors = {1};
        for(auto &pe : factors){
            int64 p = pe.first;
            int  e = pe.second;
            int sz = divisors.size();
            // for each existing divisor d, multiply by p^k for k=1..e
            for(int i = 0; i < sz; i++){
                int64 base = divisors[i];
                int64 val = base;
                for(int k = 1; k <= e; k++){
                    val *= p;
                    divisors.push_back(val);
                }
            }
        }
        sort(divisors.begin(), divisors.end());

        // Output result
        cout << "Case " << tc << ":";
        for(auto d : divisors){
            cout << " " << d;
        }
        cout << "\n";
    }
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys
import math

def compute_divisors(G):
    # Factorize G by trial division
    tmp = G
    factors = []
    # factor out 2
    if tmp % 2 == 0:
        cnt = 0
        while tmp % 2 == 0:
            tmp //= 2
            cnt += 1
        factors.append((2, cnt))
    # factor odd numbers
    p = 3
    while p * p <= tmp:
        if tmp % p == 0:
            cnt = 0
            while tmp % p == 0:
                tmp //= p
                cnt += 1
            factors.append((p, cnt))
        p += 2
    if tmp > 1:
        factors.append((tmp, 1))

    # Generate all divisors from prime powers
    divisors = [1]
    for (p, cnt) in factors:
        cur = []
        for d in divisors:
            val = d
            for _ in range(cnt):
                val *= p
                cur.append(val)
        divisors += cur

    return sorted(divisors)

def main():
    data = sys.stdin.read().strip().split()
    T = int(data[0])
    idx = 1
    out = []
    for tc in range(1, T+1):
        s = data[idx]; idx += 1
        n = len(s)

        # Build masks
        mask = {}
        place = 1
        for ch in reversed(s):
            mask[ch] = mask.get(ch, 0) + place
            place *= 10

        letters = list(mask.items())
        m = len(letters)

        # Compute G
        if m == 1:
            G = letters[0][1]
        else:
            G = 0
            for i in range(m):
                for j in range(i+1, m):
                    sumw = letters[i][1] + letters[j][1]
                    G = math.gcd(G, sumw)

        # Get all divisors
        divs = compute_divisors(G)
        out.append("Case {}: {}".format(tc, " ".join(str(d) for d in divs)))

    print("\n".join(out))

if __name__ == "__main__":
    main()
```