#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef long long ll;
typedef pair<string, ll> psi;

ll p;

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n, 0) { }
  T sum(int i, int j) {
    if (i == 0) {
      T S = 0;
      for (j; j >= 0; j = (j & (j + 1)) - 1) S = (S+x[j])%p;
      return S;
    } else return sum(0, j) - sum(0, i-1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k+1) x[k] = (x[k]+a)%p;
  }
};

int main() {
  ll a, b;
  while(cin>>a>>b>>p,a||b||p) {
    vector<psi> v;
    for (ll i=a; i<=b; ++i) {
      char tmp[30];
      sprintf(tmp, "%lld", i);
      v.push_back(psi(string(tmp), i-a));
    }
    sort(ALL(v));
    int table[b-a+1];
    REP(i, v.size()) {
      table[v[i].second] = i;
    }
    int n = b-a+1;
    // REP(i, b-a+1)
    //   cout << table[i] << " ";
    // cout << endl;

    fenwick_tree<ll> dp(n);
    REP(i, n) {
      //cout << dp.sum(0, table[i]) + 1 << " ";
      dp.add(table[i], dp.sum(0, table[i]) + 1);
    }
    //cout << endl;
    cout << dp.sum(0, n-1) << endl;
  }
}