import java.util.*;

// Checker for Is-A, Has-a

public class JohnChecker
{
    public static final int MINNM = 1;
	public static final int MAXNM = 20000;

	public static String [] lines = new String[MAXNM];

	public static void printError(int line, String msg)
	{
		System.out.println("ERROR Line " + line + ": " + msg);
		System.exit(-1);
	}

    public static void checkIntBounds(int x, int min, int max, String name, int nLines)
    {
        if (x < min || x > max)
            printError(nLines, "invalid " + name + " value: " + x);
    }

    public static void checkForRepeats(int size, int nLines)
    {
        for(int i=0; i<size-1; i++)
            if (lines[i].equals(lines[size-1]))
                printError(nLines, "repeated line " + lines[size-1]);
    }
	public static void main(String [] args)
	{
		Scanner in = new Scanner(System.in);
		int n, m, nLines = 0;
		String line;

        line = in.nextLine();
        nLines++;
        StringTokenizer st = new StringTokenizer(line);
        if (st.countTokens() != 2)
            printError(nLines, "number of values on line incorrect");
		n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
		checkIntBounds(n, MINNM, MAXNM, "n", nLines);
		checkIntBounds(m, MINNM, MAXNM, "m", nLines);
		while (in.hasNext()) {
			line = in.nextLine();
			nLines++;
			st = new StringTokenizer(line);
			if (st.countTokens() != 3) {
                printError(nLines, "number of values on line incorrect");
                continue;
			}
			String s1, s2, s3;
			s1 = st.nextToken();
			s2 = st.nextToken();
			s3 = st.nextToken();
			if (!s2.equals("is-a") && !s2.equals("has-a"))
                printError(nLines, "missing is-a/has-a");
            lines[nLines-2] = s1+" "+s2+" "+s3;
//            checkForRepeats(nLines-1, nLines);
		}
		if (in.hasNextLine())
			printError(nLines, "extra number of lines");
System.exit(42);
	}
}

