#include <bits/stdc++.h>
using namespace std;
map<int, int> vis[2];
map<int, int> previ[2];
map<int, int> func[2];
queue<int> q[2];
vector<long long> ans;
long long u, v, p;
bool notfound = 1;
int pw(long long a, long long n) {
  long long t = 1;
  for (; n; n >>= 1, (a *= a) %= p)
    if (n & 1) (t *= a) %= p;
  return t;
}
void add(int pred, int cur, int source, int type) {
  if (vis[source][cur]) return;
  vis[source][cur] = 1;
  previ[source][cur] = pred;
  if (source && type != 3) type = 3 - type;
  func[source][cur] = type;
  q[source].push(cur);
}
void Solve(int x) {
  long long t = x;
  while (previ[0][t] != t) {
    ans.push_back(func[0][t]);
    t = previ[0][t];
  }
  reverse(ans.begin(), ans.end());
  t = x;
  while (t != previ[1][t]) {
    ans.push_back(func[1][t]);
    t = previ[1][t];
  }
}
void BFS() {
  long long t, sz;
  q[0].push(u);
  vis[0][u] = 1;
  previ[0][u] = u;
  q[1].push(v);
  vis[1][v] = 1;
  previ[1][v] = v;
  while (!q[0].empty() || !q[1].empty()) {
    sz = q[0].size();
    while (sz--) {
      t = q[0].front();
      q[0].pop();
      if (vis[1][t]) {
        Solve(t);
        return;
      }
      add(t, t + 1 % p, 0, 1);
      add(t, (t + p - 1) % p, 0, 2);
      add(t, pw(t, p - 2), 0, 3);
    }
    sz = q[1].size();
    while (sz--) {
      t = q[1].front();
      q[1].pop();
      if (vis[0][t]) {
        Solve(t);
        return;
      }
      add(t, t + 1 % p, 1, 1);
      add(t, (t + p - 1) % p, 1, 2);
      add(t, pw(t, p - 2), 1, 3);
    }
  }
}
int main() {
  cin >> u >> v >> p;
  BFS();
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
}
