#include <bits/stdc++.h>
using namespace std;
const int maxn = 20008;
int n, m, pp;
int x[maxn], y[maxn];
int g[150][maxn], f[150][maxn];
vector<char> ans;
int tot, st[155];
struct Tprogram {
  void open() {
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
  }
  void close() {
    fclose(stdin);
    fclose(stdout);
  }
  void init() {
    scanf("%d%d%d", &n, &m, &pp);
    for (int i = 1; i <= n; i++) scanf("%d", &x[i]), x[i] %= pp;
    for (int i = 1; i <= m; i++) scanf("%d", &y[i]), y[i] %= pp;
  }
  void dp(int g[], int l, int r, int &last) {
    for (int i = 0; i <= m; i++) f[0][i] = g[i];
    for (int i = 1; i <= r - l + 1; i++)
      for (int j = 1; j <= m; j++) {
        int v = x[i + l - 1] + y[j];
        if (v >= pp) v -= pp;
        f[i][j] = (f[i - 1][j] > f[i][j - 1] ? f[i - 1][j] : f[i][j - 1]) + v;
      }
    int tx = r - l + 1, ty = last;
    while (tx) {
      int v = x[tx + l - 1] + y[ty];
      if (v >= pp) v -= pp;
      if (f[tx][ty] - v == f[tx - 1][ty])
        ans.push_back('C'), tx--;
      else
        ans.push_back('S'), ty--;
    }
    last = ty;
  }
  void work() {
    st[tot = 1] = 1;
    int d = sqrt(n);
    int i = 0;
    for (int k = 1; k <= n; k++) {
      i++;
      for (int j = 1; j <= m; j++) {
        int v = x[k] + y[j];
        if (v >= pp) v -= pp;
        f[i][j] = (f[i - 1][j] > f[i][j - 1] ? f[i - 1][j] : f[i][j - 1]) + v;
      }
      if (k == n) {
        printf("%d\n", f[i][m]);
      }
      if (k == st[tot]) {
        for (int j = 1; j <= m; j++) g[tot][j] = f[i][j];
        ++tot;
        st[tot] = st[tot - 1] + d;
        for (int j = 1; j <= m; j++) f[0][j] = f[i][j];
        i = 0;
      }
    }
    st[tot] = n;
    int last = m;
    for (int i = tot - 1; i >= 1; i--) {
      dp(g[i], st[i] + 1, st[i + 1], last);
    }
    for (int i = last; i >= 2; i--) ans.push_back('S');
    reverse(ans.begin(), ans.end());
    for (int i = 0; i <= (int)ans.size() - 1; i++) printf("%c", ans[i]);
  }
} Program;
int main() {
  Program.init();
  Program.work();
  return 0;
}
