#include <iostream>
#include <cmath>
using namespace std;
int SumOfDigit(int n) {
int f = 0;
while (n >= 1) {
f += n % 10;
n /= 10;
}
return f;
}
int main()
{
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
int A;
cin >> A;
int sum = 0;
double f = sqrt(A);
for (int j = 1; j*1.0 <= f; j++) {
if (A%j == 0) sum += SumOfDigit(j) + SumOfDigit(A/j);
}
if ((int) f == f) sum-=f;
cout<<sum<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgU3VtT2ZEaWdpdChpbnQgbikgewoJaW50IGYgPSAwOwoJd2hpbGUgKG4gPj0gMSkgewoJCWYgKz0gbiAlIDEwOwoJCW4gLz0gMTA7Cgl9CglyZXR1cm4gZjsKfQoKCmludCBtYWluKCkKewoJaW50IE47CgljaW4gPj4gTjsKCWZvciAoaW50IGkgPSAxOyBpIDw9IE47IGkrKykgewoJCWludCBBOwoJCWNpbiA+PiBBOwoJCWludCBzdW0gPSAwOwoJCWRvdWJsZSBmID0gc3FydChBKTsKCQlmb3IgKGludCBqID0gMTsgaioxLjAgPD0gZjsgaisrKSB7CgkJCWlmIChBJWogPT0gMCkgc3VtICs9IFN1bU9mRGlnaXQoaikgKyBTdW1PZkRpZ2l0KEEvaik7CgkJCX0KCQlpZiAoKGludCkgZiA9PSBmKSBzdW0tPWY7CgkJY291dDw8c3VtPDxlbmRsOwoJfQogICAgcmV0dXJuIDA7Cn0=