#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, cnt, sum, num, ans;
map<int, int> t1, t2, tt1, tt2;
queue<int> q;
int a[210005];
int mod;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!('0' <= c && c <= '9')) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (('0' <= c && c <= '9')) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int qpow(int a, int b) {
  a %= mod;
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
int inv(int a) { return qpow(a, mod - 2); }
void Print(int h) {
  ans++;
  if (t1[h] == n) {
    printf("%d\n%d", ans, t2[h]);
    return;
  }
  Print(t1[h]);
  printf(" %d", t2[h]);
  if (h == x)
    for (int i = 1; i <= a[0]; i++) printf(" %d", a[i]);
}
int main() {
  n = read(), m = read(), mod = read();
  if (n == m) {
    cout << 0 << endl;
    return 0;
  }
  q.push(n);
  t1[n] = -1;
  while (!q.empty() && !t2[m] && num < 210005) {
    int u = q.front();
    q.pop();
    int v = (u + 1) % mod;
    if (!t2[v]) {
      t1[v] = u, t2[v] = 1;
      q.push(v);
      num++;
    }
    v = (u + mod - 1) % mod;
    if (!t2[v]) {
      t1[v] = u, t2[v] = 2;
      q.push(v);
      num++;
    }
    v = inv(u);
    if (!t2[v]) {
      t1[v] = u, t2[v] = 3;
      q.push(v);
      num++;
    }
  }
  if (t2[m]) {
    Print(m);
    return 0;
  }
  while (!q.empty()) q.pop();
  q.push(m);
  tt1[m] = -1;
  num = 0;
  while (!q.empty() && num < 210005) {
    int u = q.front();
    q.pop();
    int v = (u + 1) % mod;
    if (!tt2[v]) {
      tt1[v] = u, tt2[v] = 2;
      q.push(v);
      num++;
      if (t2[v]) {
        x = v;
        break;
      }
    }
    v = (u + mod - 1) % mod;
    if (!tt2[v]) {
      tt1[v] = u, tt2[v] = 1;
      q.push(v);
      num++;
      if (t2[v]) {
        x = v;
        break;
      }
    }
    v = inv(u);
    if (!tt2[v]) {
      tt1[v] = u, tt2[v] = 3;
      q.push(v);
      num++;
      if (t2[v]) {
        x = v;
        break;
      }
    }
  }
  for (int i = x; i != m; i = tt1[i]) a[++a[0]] = tt2[i];
  ans = a[0];
  Print(x);
  return 0;
}
