#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, M = 1e9 + 7;
int u, v, P;
long long pp(long long n, long long p) {
  if (p == 0) return 1;
  if (p == 1) return n;
  long long x = pp(n, p / 2);
  if (p & 1) return (((x * x) % P) * n) % P;
  return (x * x) % P;
}
long long go(int i, int nm) {
  if (i == 1) return (nm + 1) % P;
  if (i == 2) return (nm - 1 + P) % P;
  return pp(nm, P - 2);
}
vector<int> vv;
map<int, pair<int, int>> mp;
void prnt(int x, int y) {
  while (x != -1) {
    vv.push_back(x);
    x = mp[x].first;
  }
  reverse(vv.begin(), vv.end());
  while (y != -1) {
    vv.push_back(y);
    y = mp[y].first;
  }
  printf("%d\n", vv.size() - 1);
  int cur = u;
  for (int i = 1; i < vv.size(); i++) {
    for (int j = 1; j <= 3; j++) {
      if (go(j, cur) == vv[i]) {
        printf("%d ", j);
        break;
      }
    }
    cur = vv[i];
  }
  exit(0);
}
void bfs() {
  queue<pair<int, int>> q;
  q.push({u, 0});
  q.push({v, 1});
  mp[u] = {-1, 0};
  mp[v] = {-1, 1};
  while (q.size()) {
    pair<int, int> s = q.front();
    q.pop();
    for (int i = 1; i <= 3; i++) {
      int x = go(i, s.first);
      if (mp.find(x) != mp.end()) {
        if (mp[x].second != s.second) {
          if (!mp[x].second)
            prnt(x, s.first);
          else
            prnt(s.first, x);
        }
        continue;
      }
      mp[x] = {s.first, s.second};
      q.push({x, s.second});
    }
  }
}
int main() {
  scanf("%d%d%d", &u, &v, &P);
  bfs();
}
