#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint operator+(mint x, mint y) { return x+=y; }

class AlternativePiles { public:
	int count(string C, int M)
	{
		vector<mint> dp((M+1)*M);
		dp[0] = 1;

		for(char c : C)
		{
			vector<mint> dp2((M+1)*M);
			for(int m=0; m<=M; ++m)
			for(int r=0; r<M; ++r) {
				int mr = m*M+r;
				if((c=='R' || c=='W') && m+1<=M)
					dp2[(m+1)*M+(r+1)%M] += dp[mr];
				if((c=='G' || c=='W') && m-1>=0)
					dp2[(m-1)*M+r] += dp[mr];
				if(c=='B' || c=='W')
					dp2[m*M+r] += dp[mr];
			}
			dp.swap(dp2);
		}
		return dp[0].val;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, AlternativePiles().count(C, M));}
int main(){

CASE(0)
	string C = "WRGWWRGW"; 
	int M = 2; 
	int _ = 3; 
END
CASE(1)
	string C = "RRGG"; 
	int M = 1; 
	int _ = 0; 
END
CASE(2)
	string C = "BBBB"; 
	int M = 5; 
	int _ = 1; 
END
CASE(3)
	string C = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"; 
	int M = 50; 
	int _ = 265470435; 
END
CASE(4)
	string C = "WRWRGWWGWWWRWBWRWGWWRWBWWRGWBWGRGWWGWGRWGRWBRWBW"; 
	int M = 7; 
	int _ = 7400348; 
END
/*
CASE(6)
	string C = ; 
	int M = ; 
	int _ = ; 
END
*/
}
// END CUT HERE
