• + 0 comments
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    #define long long long
    
    const int maxn = 210;
    const int mod = 1000000007;
    
    int n, m, s;
    char map[maxn][maxn];
    long ans[maxn][maxn];
    long sum[maxn][2*maxn];
    
    void init(){
        cin >> n >> m >> s;
        for(int i = 0; i < n; ++i)
            cin >> map[i];
    }
    
    long getsum(int x, int y){
        if(x < 0) {
            y += x;
            x = 0;
        }
        if(x >= n) {
            y = y - x + n - 1;
            x = n - 1;
        }
        if(y < 0)
            return 0;
        return sum[x][y];
    }
    
    void calc_sum(){
        for(int j = 0; j < 2 * n; ++j)
            for(int i = 0; i < n; ++i){
                if(j >= n)
                    sum[i][j] = 0;
                else
                    sum[i][j] = ans[i][j];
                sum[i][j] = (sum[i][j] + getsum(i - 1, j - 1) + getsum(i + 1, j - 1) - getsum(i, j - 2) + mod) % mod;
            }
    }
    
    void solve() {
        memset(ans, 0, sizeof(ans));
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(map[i][j] == 'L')
                    ans[i][j] = 1;
        for(int k = 1; k <= m; ++k) {
            calc_sum();
            for(int i = 0; i < n; ++i)
                for(int j = 0; j < n; ++j)
                    if(map[i][j] == 'P')
                        ans[i][j] = 0;
                    else{
                        ans[i][j] = (getsum(i, j + s) - getsum(i - s - 1, j - 1) - getsum(i + s + 1, j - 1) + getsum(i, j - s - 2) + mod + mod) % mod;
                        ans[i][j] = (ans[i][j] + getsum(i, j + s - 1) - getsum(i - s, j - 1) - getsum(i + s, j - 1) + getsum(i, j - s - 1) + mod + mod) % mod;
                    }
        }
        long res = 0;
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                res = (res + ans[i][j]) % mod;
        cout << res << endl;
    }
    
    int main() {
        int t; cin >> t;
        while(t--){
            init();
            solve();
        }
    }