#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   const int MAXM = 1100;   const int MAXK = 100100;   int n, m, k, len[MAXK], max_len[MAXN][MAXM][4];   int mm[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   char mmap[MAXN][MAXM], dir[MAXK], direction[256];   vector<pair<int, int> > possible;   vector<char> sol;   int get_max_len(int r, int c, int d) {     if (max_len[r][c][d] != -1) return max_len[r][c][d];     if (mmap[r][c] ==  # ) return -1;     int &ml = max_len[r][c][d];     ml = 0;     int nr = r + mm[d][0];     int nc = c + mm[d][1];     ml += 1 + get_max_len(nr, nc, d);     return ml;   }   bool solve(int r, int c) {     for (int i = 0; i < k; i++) {       int d = direction[(int)dir[i]];       int maxd = get_max_len(r, c, d);       if (maxd < len[i]) return false;       r += mm[d][0] * len[i];       c += mm[d][1] * len[i];     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     direction[ N ] = 1;     direction[ S ] = 0;     direction[ E ] = 2;     direction[ W ] = 3;     cin >> n >> m;     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= m + 1; j++) {         if (i == 0 || i > n || j == 0 || j > m)           mmap[i][j] =  # ;         else           cin >> mmap[i][j];         if ( A  <= mmap[i][j] && mmap[i][j] <=  Z )           possible.push_back(make_pair(i, j));         max_len[i][j][0] = -1;         max_len[i][j][1] = -1;         max_len[i][j][2] = -1;         max_len[i][j][3] = -1;       }     cin >> k;     for (int i = 0; i < k; i++) cin >> dir[i] >> len[i];     for (int i = 0; i < (int)possible.size(); i++) {       int r = possible[i].first;       int c = possible[i].second;       if (solve(r, c)) sol.push_back(mmap[r][c]);     }     if (sol.empty())       cout <<  no solution  << endl;     else {       sort(sol.begin(), sol.end());       for (int i = 0; i < (int)sol.size(); i++) cout << sol[i];       cout << endl;     }   }   