class SumBinaryIndexedTree(val size: Int, val modulo: Long) {
    private val array: LongArray = LongArray(size){0L}
    fun increase(position: Int, value: Long): Unit {
        if (position < size) {
            array[position] = (array[position] + value) % modulo
            increase(position + ((position + 1) and position.inv()), value)
        }
    }
    operator fun get(position: Int): Long {
        return if (position < 0) 0L else (array[position] + get(position - ((position + 1) and position.inv()))) % modulo
    }

}
fun main(args: Array<String>?): Unit {
    while(true) {
        val (a, b, p) = readLine()!!.trim().split(' ').map(String::toInt)
        if (a == 0) return
        val numbers = (a .. b).map(Any::toString)
        val lexical = numbers.indices.sortedBy { numbers[it] }
        val bit = SumBinaryIndexedTree(numbers.size, p.toLong())
        var result = 0L
        for (i in lexical) {
            val prev = bit[i] + 1L
            result = (result + prev) % p
            bit.increase(i, prev)
        }
        println(result)
    }
}
