#include <iostream>
#include <algorithm>
#include <queue>
#include <sstream>

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

template<class T> T getAs(){ T v; std::cin >> v; return v; }
inline int getInt(){ return getAs<int>(); }

using namespace std;

string to_str(int a){ stringstream ss; ss << a; return ss.str(); }

int mod;

template<class T>
class BIT{
  vector<T> data;
  size_t n;
public:
  BIT(size_t nn) : data(vector<int>(nn + 1)), n(nn) {}

  T sum(int i){
    T s = (T)0;
    i++;
    while(i > 0){
      s += data[i]; s %= mod;
      i -= i & -i;
    }
    return s;
  }

  void add(int i, T x){
    i++;
    while(i <= (int)n){
      data[i] += x; data[i] %= mod;
      i += i & -i;
    }
  }
};

int main(){
  while(true){
    int a = getInt();
    int b = getInt();
    int p = getInt(); mod = p;

    if(a + b + p == 0) break;

    vector<string> v(b - a + 1);
    vector<int> num(b - a + 1);
    BIT<int> bit(b - a + 2);

    REP(i, b - a + 1) v[i] = to_str(a + i);
    sort(v.begin(), v.end());
    REP(i, b - a + 1) num[i] = atoi(v[i].c_str());

    bit.add(0, 1);
    REP(i, b - a + 1){
      bit.add(num[i] - a + 1, bit.sum(num[i] - a));
    }

    cout << (p + bit.sum(b - a + 1) - 1) % p << endl;
  }
  return 0;
}