#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Battleships {
private:
    vector<vector<char>> board;
    int M, N;

public:
    Battleships(int m, int n) {
        M = m;
        N = n;
        board.resize(M, vector<char>(N));
    }

    void setBoard(const vector<string>& input) {
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                board[i][j] = input[i][j];
            }
        }
    }

    string shoot(int x, int y) {
        if (x < 0 || y < 0 || x >= M || y >= N) {
            return "Invalid Input!";
        }
        if (board[x][y] == 'B') {
            board[x][y] = 'E';
            return "Hit!";
        }
        return "Miss!";
    }
};

int main() {
    int M, N;
    cin >> M >> N;

    Battleships game(M, N);
    vector<string> board(M);

    for (int i = 0; i < M; i++) {
        cin >> board[i];
    }
    game.setBoard(board);

    while (true) {
        int x, y;
        cin >> x >> y;
        if (x == -1 && y == -1)
            break;
        cout << game.shoot(x, y) << endl;
    }

    return 0;
}
