1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 666;
const int mod = 1000000007;

char s[N][N];
char t[N*2];
int dp[N*2][N*2];

int run(int m) {
	dp[0][0] = 1;
	int pvl = 0, pvr = 0, cb = 0;
	FORI(k,m) {
		if (t[k] == 'L') cb++;
		FOR(b,cb+1) {
			dp[k][b] = dp[k-1][b];
			if (t[k] == 'L') {
				if (b > 0) {
					dp[k][b] += dp[k-1][b-1];
					if (dp[k][b] >= mod) dp[k][b] -= mod;
					if (pvl > 0) dp[k][b] += mod - dp[pvl-1][b-1];
					if (dp[k][b] >= mod) dp[k][b] -= mod;
				}
			} else {
				dp[k][b] += dp[k-1][b+1];
				if (dp[k][b] >= mod) dp[k][b] -= mod;
				if (pvr > 0) dp[k][b] += mod - dp[pvr-1][b+1];
				if (dp[k][b] >= mod) dp[k][b] -= mod;
			}
		}
		if (t[k] == 'L') pvl = k;
		else pvr = k;
		dp[k][cb+1] = 0;
	}
	int ans = (dp[m-1][0]+mod-1)%mod;
	FORI(k,m) FOR(b,cb+1) dp[k][b] = 0;
	return ans;
}

int main() {
	int n;
	scanf("%d", &n);
	FOR(i,n) scanf("%s", s[i]);
	FOR(i,n) {
		FOR(j,n) {
			int m = 1;
			for (int k = 0; s[i][k]; k++) t[m++] = s[i][k];
			for (int k = 0; s[j][k]; k++) t[m++] = s[j][k];
			printf("%d ", run(m));
		}
		printf("\n");
	}
	return 0;
}