#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        ans %= mod;
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return ans % mod;
}

string solve(string s){
    string t = "";
    rep0(i, s.size()){
        if(s[i] == s[i + 1]){
            t.push_back(s[i]);
        }else if(s[i] + s[i + 1] == 163){
            t.push_back('S');
        }else if(s[i] + s[i + 1] == 165){
            t.push_back('R');
        }else t.push_back('P');
        ++i;
    }
    s = t;
    return s;
}

//modの値の確認をすること
int main(){
    ll n,k;
    string s;
    cin >> n >> k >> s;
    rep0(i, k)s = solve(s + s);
    pf(s[0]);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>

int main(){
  int N;
  cin >> N;
  vector<vector<string>> S(9,vector<string> (256));
  S[1][1] = "AB";
  int k = 1;
  rep(i,N-1){
    rep(j,k){
      S[i+2][j+1] = S[i+1][j+1] + S[i+1][j+1];
    }
    rep(j,k){
      string T,R;
      T = S[i+1][j+1];
      rep(l,T.size()){
        if(T.at(l)=='A') R = R+"B";
        else R = R+"A";
      }
      S[i+2][k+j+1] = T + R;
    }
    rep(j,k+1){
      S[i+2][2*k+1] = S[i+2][2*k+1] + "A";
    }
    rep(j,k+1){
      S[i+2][2*k+1] = S[i+2][2*k+1] + "B";
    }
    k= 2*k+1;
  }
  cout << k << endl;
  rep(i,k){
    cout << S[N][i+1] << endl;
  }
}