#include <bits/stdc++.h>
using namespace std;
long long u, v, p;
inline long long pw(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) (ans *= x) %= p;
    x = x * x % p;
    y >>= 1;
  }
  return ans;
}
map<long long, long long> M, pre, Vis, nxt;
queue<long long> q, q2;
int stk[1000], top = 0;
int main() {
  scanf("%lld%lld%lld", &u, &v, &p);
  q.push(u);
  M[u] = 1;
  pre[u] = -1;
  q2.push(v);
  Vis[v] = 1;
  nxt[v] = -1;
  while (!q.empty()) {
    long long x = q.front(), f;
    q.pop();
    if (Vis[x]) {
      printf("%lld\n", M[x] + Vis[x] - 2);
      int v = x;
      while (v != -1) stk[++top] = v, v = pre[v];
      for (int i = top; i > 1; --i) {
        if ((stk[i] + 1) % p == stk[i - 1])
          printf("1 ");
        else if ((stk[i] + p - 1) % p == stk[i - 1])
          printf("2 ");
        else
          printf("3 ");
      }
      while (nxt[x] != -1) {
        if ((x + 1) % p == nxt[x])
          printf("1 ");
        else if ((x + p - 1) % p == nxt[x])
          printf("2 ");
        else
          printf("3 ");
        x = nxt[x];
      }
      return 0;
    }
    if (!M[f = (x + 1) % p]) q.push(f), M[f] = M[x] + 1, pre[f] = x;
    if (!M[f = (x + p - 1) % p]) q.push(f), M[f] = M[x] + 1, pre[f] = x;
    if (!M[f = pw(x, p - 2)]) q.push(f), M[f] = M[x] + 1, pre[f] = x;
    x = q2.front();
    q2.pop();
    if (!Vis[f = (x + 1) % p]) q2.push(f), Vis[f] = Vis[x] + 1, nxt[f] = x;
    if (!Vis[f = (x + p - 1) % p]) q2.push(f), Vis[f] = Vis[x] + 1, nxt[f] = x;
    if (!Vis[f = pw(x, p - 2)]) q2.push(f), Vis[f] = Vis[x] + 1, nxt[f] = x;
  }
  return 0;
}
