#include <bits/stdc++.h>
using namespace std;
int xv[20000], yv[20000], n, m, p;
int modp[40001];
pair<int, int> dp[2][20000];
inline int f(int a, int b) { return modp[xv[a] + yv[b]]; }
void solve(int sx, int sy, int fx, int fy, bool print = false) {
  int dist = fx - sx - 1 + fy - sy - 1;
  int score = f(sx, sy);
  if (dist == 1) {
    score += f(fx - 1, fy - 1);
    if (print) {
      printf("%d\n", score);
    }
    if (fx == sx + 2)
      putchar('C');
    else
      putchar('S');
    return;
  }
  int half = dist / 2;
  pair<int, int> *cur = dp[0], *next = dp[1];
  for (int x = sx; x < fx; x++) {
    cur[x].first = (x == 0 ? 0 : f(x, sy) + cur[x - 1].first);
    cur[x].second = ((sx + half) << 16) + (sy);
  }
  for (int y = sy + 1; y < fy; y++) {
    next[sx].first = cur[sx].first + f(sx, y);
    next[sx].second = (sx << 16) + (sy + half);
    for (int x = sx + 1; x < fx; x++) {
      int vc = next[x - 1].first;
      int vs = cur[x].first;
      if (vc > vs) {
        next[x].first = vc + f(x, y);
        if (x + y == sx + sy + half)
          next[x].second = (x << 16) + y;
        else
          next[x].second = next[x - 1].second;
      } else {
        next[x].first = vs + f(x, y);
        if (x + y == sx + sy + half)
          next[x].second = (x << 16) + y;
        else
          next[x].second = cur[x].second;
      }
    }
    swap(cur, next);
  }
  if (print) {
    score += cur[fx - 1].first;
    printf("%d\n", score);
  }
  int hx = (cur[fx - 1].second >> 16) & 65535;
  int hy = (cur[fx - 1].second) & 65535;
  solve(sx, sy, hx + 1, hy + 1);
  solve(hx, hy, fx, fy);
}
void read() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%d", xv + i);
  for (int i = 0; i < m; i++) scanf("%d", yv + i);
}
void randcase() {
  n = 20000, m = 20000, p = 12345;
  for (int i = 0; i < n; i++) xv[i] = rand() % 20000;
  for (int i = 0; i < m; i++) yv[i] = rand() % 20000;
}
int main() {
  read();
  for (int i = 0; i <= 40000; i++) modp[i] = i % p;
  if (n == 1 && m == 1) {
    printf("%d\n\n", f(0, 0));
    return 0;
  }
  solve(0, 0, n, m, true);
  return 0;
}
