#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
int N[1001][1001];
int S[1001][1001];
int W[1001][1001];
int E[1001][1001];
int k;
int num[1000000];
char typ[1000000];
int n, m;
vector<char> ret;
bool ok(int x, int y) {
  for (int i = 0; i < k; i++) {
    if (typ[i] == 'N') {
      if (x - num[i] > N[x][y])
        x = x - num[i];
      else
        return 0;
    } else if (typ[i] == 'S') {
      if (x + num[i] < S[x][y])
        x = x + num[i];
      else
        return 0;
    } else if (typ[i] == 'W') {
      if (y - num[i] > W[x][y])
        y = y - num[i];
      else
        return 0;
    } else {
      if (y + num[i] < E[x][y])
        y = y + num[i];
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    int mx = -1;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') mx = j;
      W[i][j] = mx;
    }
  }
  for (int i = 0; i < n; i++) {
    int mx = m;
    for (int j = m - 1; j >= 0; j--) {
      if (a[i][j] == '#') mx = j;
      E[i][j] = mx;
    }
  }
  for (int i = 0; i < m; i++) {
    int mx = -1;
    for (int j = 0; j < n; j++) {
      if (a[j][i] == '#') mx = j;
      N[j][i] = mx;
    }
  }
  for (int i = 0; i < m; i++) {
    int mx = n;
    for (int j = n - 1; j >= 0; j--) {
      if (a[j][i] == '#') mx = j;
      S[j][i] = mx;
    }
  }
  cin >> k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> typ[i] >> num[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] >= 'A' && a[i][j] <= 'Z')
        if (ok(i, j)) ret.push_back(a[i][j]);
    }
  }
  if (ret.size() == 0) {
    cout << "no solution" << endl;
    return 0;
  }
  sort(ret.begin(), ret.end());
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i];
  }
  cout << endl;
}

### Prompt

In Cpp, your task is to solve the following problem:

Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.

The treasure map can be represented as a rectangle n × m in size. Each cell stands for an islands' square (the square's side length equals to a mile). Some cells stand for the sea and they are impenetrable. All other cells are penetrable (i.e. available) and some of them contain local sights. For example, the large tree on the hills or the cave in the rocks.

Besides, the map also has a set of k instructions. Each instruction is in the following form:

"Walk n miles in the y direction"

The possible directions are: north, south, east, and west. If you follow these instructions carefully (you should fulfill all of them, one by one) then you should reach exactly the place where treasures are buried. 

Unfortunately the captain doesn't know the place where to start fulfilling the instructions — as that very piece of the map was lost. But the captain very well remembers that the place contained some local sight. Besides, the captain knows that the whole way goes through the island's penetrable squares.

The captain wants to know which sights are worth checking. He asks you to help him with that. 

Input

The first line contains two integers n and m (3 ≤ n, m ≤ 1000).

Then follow n lines containing m integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are marked with uppercase Latin letters from "A" to "Z". Not all alphabet letters can be used. However, it is guaranteed that at least one of them is present on the map. All local sights are marked by different letters.

The next line contains number k (1 ≤ k ≤ 105), after which k lines follow. Each line describes an instruction. Each instruction possesses the form "dir len", where dir stands for the direction and len stands for the length of the way to walk. dir can take values "N", "S", "W" and "E" for North, South, West and East correspondingly. At that, north is to the top, South is to the bottom, west is to the left and east is to the right. len is an integer from 1 to 1000.

Output

Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes.

Examples

Input

6 10
##########
#K#..#####
#.#..##.##
#..L.#...#
###D###A.#
##########
4
N 2
S 1
E 1
W 2


Output

AD

Input

3 4
####
#.A#
####
2
W 1
N 2


Output

no solution

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
int N[1001][1001];
int S[1001][1001];
int W[1001][1001];
int E[1001][1001];
int k;
int num[1000000];
char typ[1000000];
int n, m;
vector<char> ret;
bool ok(int x, int y) {
  for (int i = 0; i < k; i++) {
    if (typ[i] == 'N') {
      if (x - num[i] > N[x][y])
        x = x - num[i];
      else
        return 0;
    } else if (typ[i] == 'S') {
      if (x + num[i] < S[x][y])
        x = x + num[i];
      else
        return 0;
    } else if (typ[i] == 'W') {
      if (y - num[i] > W[x][y])
        y = y - num[i];
      else
        return 0;
    } else {
      if (y + num[i] < E[x][y])
        y = y + num[i];
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    int mx = -1;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') mx = j;
      W[i][j] = mx;
    }
  }
  for (int i = 0; i < n; i++) {
    int mx = m;
    for (int j = m - 1; j >= 0; j--) {
      if (a[i][j] == '#') mx = j;
      E[i][j] = mx;
    }
  }
  for (int i = 0; i < m; i++) {
    int mx = -1;
    for (int j = 0; j < n; j++) {
      if (a[j][i] == '#') mx = j;
      N[j][i] = mx;
    }
  }
  for (int i = 0; i < m; i++) {
    int mx = n;
    for (int j = n - 1; j >= 0; j--) {
      if (a[j][i] == '#') mx = j;
      S[j][i] = mx;
    }
  }
  cin >> k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> typ[i] >> num[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] >= 'A' && a[i][j] <= 'Z')
        if (ok(i, j)) ret.push_back(a[i][j]);
    }
  }
  if (ret.size() == 0) {
    cout << "no solution" << endl;
    return 0;
  }
  sort(ret.begin(), ret.end());
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i];
  }
  cout << endl;
}

```