#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const int MODVAL = 1000000007;
struct mint
{
	int val;
	mint():val(0){}
	mint(int    x):val(x%MODVAL) {}
	mint(size_t 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 = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint operator/(mint x, mint y) { return x/=y; }
vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; }
mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }

class SRMChallengePhase { public:
	int countWays(vector <string> codersAttempted, vector <string> codersChallenged)
	{
		string at = accumulate(codersAttempted.begin(), codersAttempted.end(), string(""));
		string sc = accumulate(codersChallenged.begin(), codersChallenged.end(), string(""));
		const int N = at.size();
		int NN=0, NY=0, YN=0, YY=0;
		for(int i=0; i<N; ++i)
			if( at[i]=='N' )
				(sc[i]=='N' ? NN : NY) ++;
			else
				(sc[i]=='N' ? YN : YY) ++;
		return solve(NN, NY, YN, YY);
	}

	int solve(int NN, int NY, int YN, int YY)
	{
		memo.clear();
		TOTAL = NN+NY+YN+YY;
		return rec(YN, NY, YY).val;
	}

	map<pair<pair<int,int>,int>, mint> memo;
	int TOTAL;
	mint rec(int YN, int NY, int YY)
	{
		if(YN+YY < YY+NY)
			return 0;
		if(YN==0 && YY==0)
			return 1;

		pair<pair<int,int>,int> key(make_pair(YN,NY),YY);
		if( memo.count(key) )
			return memo[key];
		mint ans = 0;

		// YN, unsuc
		if(YN) ans += rec(YN-1, NY, YY) * YN * (TOTAL-1);
		// YN, suc
		if(YN&&NY) ans += rec(YN-1, NY-1, YY) * YN * NY;
		// YY, unsuc
		if(YY) ans += rec(YN, NY+1, YY-1) * YY * (TOTAL-1);
		// YY, suc
		if(YY&&NY) ans += rec(YN, NY, YY-1) * YY * NY;
		return memo[key] = ans;
	}
};

// 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(_, SRMChallengePhase().countWays(codersAttempted, codersChallenged));}
int main(){

CASE(0)
	string codersAttempted_[] = {"YY"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"NY"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 1; 
END
CASE(1)
	string codersAttempted_[] = {"YY", "NN"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"N", "NYY"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 4; 
END
CASE(2)
	string codersAttempted_[] = {"YNNN"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"NYY", "Y"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 0; 
END
CASE(3)
	string codersAttempted_[] = {"N"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"N"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 1; 
END
CASE(4)
	string codersAttempted_[] = {"YYY"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"NNY"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 24; 
END
CASE(5)
	string codersAttempted_[] = {"YY", "N", "YYYY", "NN", "YYYYY"};
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = {"N", "YYYYY", "N", "Y", "N", "YYYY", "N"};
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = 807026001; 
END
/*
CASE(6)
	string codersAttempted_[] = ;
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = ;
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = ; 
END
CASE(7)
	string codersAttempted_[] = ;
	  vector <string> codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); 
	string codersChallenged_[] = ;
	  vector <string> codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
