#include<iostream>
#include<vector>
#include<map>
using namespace std;
int _C3(int n, int k)
{
	if(k > n)
		return 0;
	else if(n==2 && k==1)
		return 2;
	else
		return 1;
}
int C(int n, int k)
{
	int ans = 1;
	while(n > 0 || k > 0)
	{
		ans = (ans*_C3(n%3, k%3))%3;
		n /= 3;
		k /= 3;
	}
	return ans;
}
int main()
{
	string x = "RWB";
	map<char,int> conv;
	for(int i = 0; i < 3; i++)
		conv[x[i]] = i;

	/***
		R W B
	R   R B W
	W   B W R
	B   W R B
	***/
	vector<vector<char>> huh = {{'R','B','W'},{'B','W','R'},{'W','R','B'}};

	int n; cin >> n;
	string orig; cin >> orig;

	string s;
	if(n&1)
		s = orig;
	else
	{
		s = "";
		n--;
		for(int i = 0; i < n; i++)
			s += huh[conv[orig[i]]][conv[orig[i+1]]];
	}


	int ans = 0;
	for(int i = 0; i <= n; i++)
		ans += C(n-1, i)*conv[s[i]];
	ans %= 3;

	cout<<x[ans]<<endl;

	return 0;
}
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <functional>
template <typename T>
inline void hash_combine(std::size_t &seed, const T &val) {
    seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename T> inline void hash_val(std::size_t &seed, const T &val) {
    hash_combine(seed, val);
}
template <typename T, typename... Types>
inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {
    hash_combine(seed, val);
    hash_val(seed, args...);
}
template <typename... Types>
inline std::size_t hash_val(const Types &... args) {
    std::size_t seed = 0;
    hash_val(seed, args...);
    return seed;
}
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator()(const std::pair<T1, T2> &p) const {
        return hash_val(p.first, p.second);
    }
};
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define G 3
#define MAX_N 300005
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef complex<double> E;
ll pow_mod(ll x,ll n){
    ll ret=1;
    while(n>0){
        if(n&1)ret=ret*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
ll n,p;
int main(){
    cin>>n>>p;
    cout<<(p-1)*pow_mod(p-2,n-1)%mod;
    return 0;
}