import math
import os
import random
import re
import sys

# Complete the findDigits function below.
def findDigits(n):
    c=0
    for d in str(n):
        try:
            if(n%int(d)==0):
                c=c+1
        except ZeroDivisionError:
            continue
    return c
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    t = int(input())

    for t_itr in range(t):
        n = int(input())

        result = findDigits(n)

        fptr.write(str(result) + '\n')

    fptr.close()