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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))

#define MOO(i,a,b) for (int i=a; i<b; i++)
#define M00(i,a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)

#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _<< " _ " <<

#define int long long

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;

const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 1e9+7;
const int MAXN = 601;

int32_t main() { FAST
  int n;
  cin >> n;

  vvi leftL;
  vvi rightL;
  vvi leftP;
  vvi rightP;
  vi base(n, 0);

  vi test(MAXN, 100);

  for (int i = 0; i < n; i++){
    string s;
    cin >> s;

    int m = s.length();

    vi nL(m);
    vi nP(m);

    int ll = m;
    int lp = m + 1;
    
    for (int j = m - 1; j >= 0; j--){
      nL[j] = ll;
      nP[j] = lp;

      if (s[j] == 'L'){
        ll = j;
      } else {
        lp = j;
      }
    }

    vvi dp(m + 2, vi(MAXN, 0));
    dp[ll][1] += 1;

    for (int j = 0; j < m; j++){
      for (int k = 0; k < MAXN; k++){
        if (k < MAXN - 1){
          dp[nL[j]][k + 1] += dp[j][k];
          if (dp[nL[j]][k + 1] >= MOD) dp[nL[j]][k + 1] -= MOD;
        }

        if (k){
          dp[nP[j]][k - 1] += dp[j][k];
          if (dp[nP[j]][k - 1] >= MOD) dp[nP[j]][k - 1] -= MOD;
        }
      }
      base[i] += dp[j][0];
      if (base[i] >= MOD) base[i] -= MOD;
    }
    leftL.pb(dp[m]);
    leftP.pb(dp[m + 1]);


    vvi dq(m + 2, vi(MAXN, 0));
    for (int j = 0; j < m; j ++) dq[j][0] = 1;
    for (int j = m - 1; j >= 0; j--){
      for (int k = 0; k < MAXN; k++){
        if (k < MAXN - 1){
          dq[j][k] += dq[nL[j]][k + 1];
        }

        if (k){
          dq[j][k] += dq[nP[j]][k - 1];
        }

        if (dq[j][k] >= MOD) dq[j][k] -= MOD;
      }
    }
    rightL.pb(dq[ll]);
    rightP.pb(dq[lp]);
  }

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      int out = base[i];
      for (int k = 0; k < MAXN; k++){
        out += (leftL[i][k] * rightL[j][k]) % MOD;
        out += (leftP[i][k] * rightP[j][k]) % MOD;
      }
      cout << (out % MOD) << ' ';
    }
    cout << '\n';
  }
}