import java.io.*;
import java.util.*;

public class Interact {
    private static String fileName = "ordeal";

    final BufferedReader stdin;
    final Scanner fin;
    final PrintWriter fout;

    AnswerQuery exactAns;

    Interact(String inputFileName, String outputFileName) throws IOException {
	stdin = new BufferedReader(new InputStreamReader(System.in));
	fin = new Scanner(new FileReader(inputFileName));
	fout = new PrintWriter(new FileWriter(outputFileName), true);
    }

    void close() {
	fin.close();
	fout.close();
    }

    static class PresentationException extends Exception {
	PresentationException(String message) {
	    super(message);
	}
    }

    void go() {
	try {
	    fout.println(interact());
	} catch (PresentationException e) {
	    fout.println("PE " + e.getMessage());
	} catch (IOException e) {
	    fout.println("FAIL " + e.getMessage());
	}
    }

    long calcHash(VectorQuery qu) {
	long res = 0, pow = 1;
	String s = qu.ans;
	for (int i = 0; i < s.length(); i++) {
	    res += pow * (s.charAt(i) - 'a' + 1);
	    pow *= exactAns.base;
	    res %= exactAns.module;
	    pow %= exactAns.module;
	}
	return res;
    }

    String interact() throws IOException, PresentationException {
	int maxQueries = 10 + 1;
	writeLine("start");
	exactAns = new AnswerQuery(fin.nextInt(), fin.nextInt());
	for (int queries = 0; queries <= maxQueries; queries++) {
	    Query qu = readRequest();
	    if (qu instanceof VectorQuery) {
		long res = calcHash(((VectorQuery) qu));
		writeLine(Long.toString(res));
	    } else if (qu instanceof AnswerQuery) {
		AnswerQuery ans = ((AnswerQuery) qu);
		return (ans.base == exactAns.base && ans.module == exactAns.module) ? (String
			.format("OK %d queries (%d, %d)", queries, ans.base,
				ans.module)) : (String.format(
			"WA too imprecise (expected (%d, %d), found (%d, %d))",
			exactAns.base, exactAns.module, ans.base, ans.module));
	    }
	}
	return "WA queries limit reached";
    }

    static class Query {
    }

    static class VectorQuery extends Query {
	String ans;

	public VectorQuery(String ans) {
	    super();
	    this.ans = ans;
	}

    }

    static class AnswerQuery extends Query {
	int base, module;

	public AnswerQuery(int base, int module) {
	    super();
	    this.base = base;
	    this.module = module;
	}

    }

    private Query readRequest() throws PresentationException, IOException {
	String line = readLine();
	String[] tokens = line.split(" ");
	if (tokens.length == 3 && tokens[0].equals("answer:")) {
	    try {
		int base = Integer.parseInt(tokens[1]);
		int mod = Integer.parseInt(tokens[2]);
		return new AnswerQuery(base, mod);
	    } catch (NumberFormatException e) {
		throw new PresentationException("answer is not a integer");
	    }
	} else if (tokens.length == 1 && tokens[0].length() <= 1000) {
	    try {
		for (int i = 0; i < tokens[0].length(); i++)
		    if (tokens[0].charAt(i) < 'a' || tokens[0].charAt(i) > 'z')
			throw new PresentationException("incorrect charecter");
		return new VectorQuery(tokens[0]);
	    } catch (NumberFormatException e) {
		throw new PresentationException("incorrect weighing");
	    }
	} else {
	    throw new PresentationException("incorrect Query");
	}
    }

    private String readLine() throws PresentationException, IOException {
	String s = stdin.readLine();
	if (s == null) {
	    throw new PresentationException("terminated too early");
	}
	fout.print("INP ");
	fout.println(s);
	return s;
    }

    private void writeLine(String s) {
	fout.print("OUT ");
	fout.println(s);
	fout.flush();
	System.out.println(s);
	System.out.flush();
    }

    public static void main(String[] args) throws IOException {
	Locale.setDefault(Locale.US);
	Interact instance = new Interact(args.length >= 2 ? args[0]
		: "ordeal.in", args.length >= 2 ? args[1] : "ordeal.out");
	instance.go();
	instance.close();
    }
}
