class FenwickTree
    def initialize(n)
        @size = n 
        @ary = [0] * (n + 1)
    end 

    def add(i, x)
        return if i > @size
        @ary[i] += x
        add(i + (i & -i), x)
    end 

    def sum(i)
        return 0 if i == 0
        @ary[i] + sum(i - (i & -i))
    end 

    attr_reader :size
end

loop do
    a, b, mod = gets.split.map(&:to_i)
    break if a == 0
    tree = FenwickTree.new(b - a + 1)
    (a..b).map(&:to_s).sort.each do |s| 
        i = s.to_i - a + 1 
        tree.add(i, (1 + tree.sum(i - 1)) % mod)
    end 
    p tree.sum(b - a + 1) % mod 
end