This page is still under construction.

Parts of this page are still being built. What you see may change.

Holodeck Hacking

Time limit2sMemory limit128 MB

Summary
Count the positive integers X whose sum with their digit reversal equals the given Y.
Level

Medium7 of 10

Topics
Backtracking, Math
Solved
No attempts yet

Problem

Someone left a physical mirror inside the holodeck chamber and it scrambled part of the simulation data. The mirror laid the reversed data on top of the original data. You have to work out how badly the data is scrambled.

Given a positive integer YY, count the distinct positive integers XX with Y=X+rev(X)Y = X + \mathrm{rev}(X). The rev\mathrm{rev} operator reverses the digits of a number. Each XX must be written in ordinary decimal form, with no leading zeros. For example, rev(350)=53\mathrm{rev}(350) = 53 and rev(53)=35\mathrm{rev}(53) = 35.

Input

The first line has one integer TT (1≤T≤5001 \le T \le 500), the number of test cases. Each test case is a single line with one integer YY (1≤Y<10181 \le Y < 10^{18}).

Output

For each test case, print one line with the count of positive integers whose sum with their own reverse equals YY.

Examples1

  1. Example 1

    Input
    8
    10
    11
    121
    299999999999999981
    109
    7087
    59284
    10201
    
    Expected output
    1
    1
    9
    1
    0
    0
    0
    1