from functools import * M = 10**9+7 for tc in range(int(input())): N = int(input()); D = [*map(int, str(N))] @cache def dp(d, t, s, bm): if d == len(D): return {bm or 1:1} z = {} for i in range((D[d]+1, 10)[t]): for k, v in dp(d+1, t|(i