T = int(raw_input())

for _ in xrange(T):
    N = int(raw_input())
    fact = 1
    for i in xrange(1,N+1):
        fact = fact * i
    print sum(map(int,list(str(fact))))
e0a9205d4e01bbfd1f52305088fdc4187cf51150
T = int(raw_input())

for _ in xrange(T):
    N = int(raw_input())
    fact = 1
    for i in xrange(1,N+1):
        fact = fact * i
    print sum(map(int,list(str(fact))))