def abakus(t):
    counter = 0
    ls = []
    for i in range(1, t + 1):
        j  = i % 10
        d = i // 10
        s = i // 100
        if i < 10:
            temp = j
        elif i < 100:
            temp = j * d
        elif i < 1000:
            temp = j * d * s

        if temp not in ls:
            ls.append(temp)
    counter = len(ls)
    return counter


n = int(input())
for i in range(n):
    k = int(input())
    print(abakus(k))