#include <bits/stdc++.h>
using namespace std;
long long int u, v, p;
map<long long int, bool> q;
map<long long int, bool> q1;
map<long long int, long long int> p1;
map<long long int, long long int> p2;
map<long long int, long long int> num;
map<long long int, long long int> num1;
map<long long int, long long int> ans;
map<long long int, long long int> ans1;
long long int qwq[1000001];
long long int qaq[1000001];
int mi(int x) {
  long long int ans = 1, base = x;
  long long int mod = p - 2;
  while (mod) {
    if (mod & 1) ans = (ans * base) % p;
    base = (base * base) % p;
    mod >>= 1;
  }
  return ans;
}
void print1(int x) {
  if (p1[x] == -1) return;
  print1(p1[x]);
  cout << num[x] << " ";
}
void print2(int x) {
  if (p2[x] == -1) return;
  cout << num1[x] << " ";
  print2(p2[x]);
}
void print(int x) {
  print1(x);
  print2(x);
}
void bfs() {
  long long int head = 0, end = 1, head1 = 0, end1 = 1;
  q[u] = 1;
  q1[v] = 1;
  p1[u] = -1;
  p2[v] = -1;
  qaq[1] = v;
  qwq[1] = u;
  long long int a, a1;
  while (1) {
    a = qwq[++head];
    long long int b = a + 1;
    if (b >= 0 && q[b] == 0) {
      b %= p;
      q[b] = 1;
      qwq[++end] = b;
      ans[b] = ans[a] + 1;
      p1[b] = a;
      num[b] = 1;
      if (q1[b] == 1) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
    b = a - 1;
    if (b >= 0 && q[b] == 0) {
      b %= p;
      q[b] = 1;
      qwq[++end] = b;
      ans[b] = ans[a] + 1;
      p1[b] = a;
      num[b] = 2;
      if (q1[b] == 1) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
    b = mi(a);
    if (b >= 0 && q[b] == 0) {
      b %= p;
      q[b] = 1;
      qwq[++end] = b;
      ans[b] = ans[a] + 1;
      p1[b] = a;
      num[b] = 3;
      if (q1[b]) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
    a1 = qaq[++head1];
    b = a1 + 1;
    if (b >= 0 && q1[b] == 0) {
      b %= p;
      q1[b] = 2;
      qaq[++end1] = b;
      ans1[b] = ans1[a1] + 1;
      p2[b] = a1;
      num1[b] = 2;
      if (q[b]) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
    b = a1 - 1;
    if (b >= 0 && q1[b] == 0) {
      b %= p;
      q1[b] = 1;
      qaq[++end1] = b;
      ans1[b] = ans1[a1] + 1;
      p2[b] = a1;
      num1[b] = 1;
      if (q[b]) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
    b = mi(a1);
    if (b >= 0 && q1[b] == 0) {
      b %= p;
      q1[b] = 1;
      qaq[++end1] = b;
      ans1[b] = ans1[a1] + 1;
      p2[b] = a1;
      num1[b] = 3;
      if (q[b] == 1) {
        cout << ans[b] + ans1[b] << endl;
        print(b);
        return;
      }
    }
  }
}
int main() {
  cin >> u >> v >> p;
  if (u == v) {
    cout << 0;
    return 0;
  }
  bfs();
  return 0;
}
