#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

template<class T>
class Fenwick{
public:
  vector<T> data;
  int n;
  Fenwick(){};
  Fenwick(int tn){
    data.resize(tn,0);
    n = tn;
  }
  T read(int idx,int tidx,ll mod){
    T sum = 0;
    if (idx == 0){
      while(tidx > 0){
	sum=(sum+data[tidx])%mod;
	tidx-=(tidx&-tidx);
      }
      return sum;
    }else return (read(0,tidx,mod)-read(0,idx-1,mod)+mod)%mod;
  }
  void update(int idx,T val,ll mod){
    while(idx <= n){
      data[idx]=(data[idx]+val)%mod;
      idx+=(idx & -idx);
    }
  }
};

int main(){
  ll a,b,p;
  while(cin>>a>>b>>p && p){
    Fenwick<ll> dp(100002);
    vector<int> num(b-a+2);
    vector<string> all;
    for(ll i=a;i<=b;i++){
      string tmp="";
      ll now = i;
      while(now)tmp=tmp+string(1,'0'+now%10),now/=10;
      reverse(tmp.begin(),tmp.end());
      all.push_back(tmp);
    }
    sort(all.begin(),all.end());
    for(int i=0;i<all.size();i++){
      ll tmp = atoi(all[i].c_str());
      num[tmp-a]=i+1;
    }

    for(ll i=a;i <= b;i++){
      int now = num[i-a];
      ll tmp = (dp.read(0,now-1,p)+1)%p;//+1 is itself
      dp.update(now,tmp,p);
    }
    cout << dp.read(0,b-a+1,p) << endl;

  }
  return false;
}