Subsets whose lexicographic order matches

Count non-empty subsets of the integers from A to B whose numeric order equals their lexicographic decimal order, modulo P.

Hard8CombinatoricsDynamic programmingTrieMathNo attempts yetTime limit8sMemory limit512 MB

Problem

Consider sets of natural numbers. In some sets, sorting the elements by value and sorting their decimal representations lexicographically give the same order. {2, 27, 3125, 9000} is such a set. {2, 27, 243} is not, because lexicographic sorting gives {2, 243, 27}.

Take the set of all integers from AA to BB inclusive and count the subsets that have this property. The empty set is not counted. The count can grow very large, so print it modulo PP, which is given in the input.

Input

The input holds several datasets. Each dataset is one line with three integers AA, BB, and PP separated by a space. They satisfy 1A1091 \le A \le 10^9, 0BA<1050 \le B - A < 10^5, and 1P1091 \le P \le 10^9.

A line holding three zeros marks the end of the input. Do not process that line.

Output

For each dataset, print the number of subsets modulo PP on its own line.