#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#define MAX_FIRED 200

char already_fired[MAX_FIRED][4];  // e.g. "A10"
int fired_count = 0;

int already_fired_contains(const char *pos) {
    for (int i = 0; i < fired_count; i++) {
        if (strcmp(already_fired[i], pos) == 0) {
            return 1;
        }
    }
    return 0;
}

void already_fired_add(const char *pos) {
    if (fired_count < MAX_FIRED) {
        strcpy(already_fired[fired_count++], pos);
    }
}

int main(void) {
    char line[256];
    char pos[4];

    srand((unsigned int)(time(NULL) ^ getpid()));

    while (fgets(line, sizeof(line), stdin)) {

        // GAME STARTED → place ships
        if (strncmp(line, "GAME STARTED", 12) == 0) {
            printf("PLACE B A1 N\n");
            printf("PLACE B C1 N\n");

            printf("PLACE C E1 N\n");

            printf("PLACE D G1 N\n");
            printf("PLACE D I1 N\n");

            printf("PLACE P A7 D\n");
            printf("PLACE P A9 D\n");
            printf("PLACE P H8 N\n");

            printf("READY\n");
            fflush(stdout);
        }

        // YOUR TURN → fire randomly
        if (strncmp(line, "YOUR TURN", 9) == 0) {
            do {
                int row = rand() % 10 + 1;       // 1–10
                char row_char = 'A' + row - 1;   // A–J
                int col = rand() % 10 + 1;       // 1–10

                snprintf(pos, sizeof(pos), "%c%d", row_char, col);
            } while (already_fired_contains(pos));

            printf("FIRE %s\n", pos);
            fflush(stdout);
            already_fired_add(pos);
        }

        // GAME OVER → exit
        if (strncmp(line, "GAME OVER", 9) == 0) {
            return 0;
        }
    }

    return 0;
}
