#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int M;

template<class T>
class FenwickTree{
	vector<T> a;
public:
	FenwickTree(int n):a(n){}
	T sum(int i,int j)const{
		if(i==0){
			T s=0;
			for(;j>=0;j=(j&(j+1))-1) s=(s+a[j])%M;
			return s;
		}
		return ((sum(0,j)-sum(0,i-1))%M+M)%M;
	}
	void add(int i,T v){
		for(;i<a.size();i|=i+1) a[i]=(a[i]+v)%M;
	}
};

int ofset;
char s[100001][16];
bool lex(int a,int b){
	return strcmp(s[a-ofset],s[b-ofset])<0;
}

int main(){
	for(int a,b;scanf("%d%d%d",&a,&b,&M),a;){
		ofset=a;
		int n=b-a+1,seq[100000];
		rep(i,n){
			seq[i]=a+i;
			sprintf(s[i],"%d",a+i);
		}
		sort(seq,seq+n,lex);

		FenwickTree<int> F(b-a+1);
		rep(i,n) F.add(seq[i]-a,F.sum(0,seq[i]-a)+1);

		printf("%d\n",F.sum(0,n-1));
	}

	return 0;
}