#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int t;
    cin>>t;
    for(int k=1;k<=t;++k)
    {
        long long n;
        cin>>n;
        int ans=0;
        long long m=n;
        while(m!=0)
        {
            int d=m%10;
            if(d!=0)
                if(n%d==0 )
                    ++ans;
            m/=10;
        }   
        cout<<ans<<endl;
    }
    
    return 0;
}