// Arup Guha
// 4/8/2024
// Checker for Spring 2024 COP 3503 Program 5

import java.util.*;
import java.io.*;

public class check_codes {

	final public static int N = 6;

	public static void main(String[] args) throws Exception {
	
		Scanner stdin = new Scanner(new File(args[0]));
		Scanner studentOut = new Scanner(new File(args[1]));
		Scanner sol = new Scanner(new File(args[2]));
		
		// Get # of drugs and codes.
		int nD = stdin.nextInt();
		int nC = stdin.nextInt();
		
		// Read in drugs.
		String[] drugs = new String[nD];
		for (int i=0; i<nD; i++)
			drugs[i] = stdin.next();
		
		// Read in codes.
		String[] codes = new String[nC];
		for (int i=0; i<nC; i++)
			codes[i] = stdin.next();
		
		// Get all student output, tokenized.
		ArrayList<String> student = new ArrayList<String>();
		while (studentOut.hasNext())
			student.add(studentOut.next());
		
		String realres = sol.next();
		
		// This is easy to grade, but only for Task 1.
		if (realres.equals("no")) {
			
			if (student.size() == 1 && student.get(0).equals("no"))
				System.out.println("Worth 2 points for Task 1.");
			else
				System.out.println("Worth 0 points for Task 1.");
		}
		
		// Used for all three tasks.
		else {
			
			int score1 = 0, score2 = 0, score3 = 0;
			
			// Tried at least 1 and 2.
			if (student.size() == 1+nD && student.get(0).equals("yes")) {
				
				score1 = 2;
				
				// Get lexicographical first matching.
				ArrayList<String> correct = new ArrayList<String>();
				for (int i=0; i<nD; i++)
					correct.add(sol.next());
		
				// This check is easiest.
				boolean allgood = true;
				for (int i=0; i<nD; i++)
					if (!student.get(i+1).equals(correct.get(i)))
						allgood = false;
					
				// Got both tasks 2 and 3.
				if (allgood) {
					score2 = 2;
					score3 = 2;
				}
				
				// Here we see if the matching is valid.
				else {
					
					// Mark which codes have been used.
					boolean[] usedcodes = new boolean[nC];
					boolean ok = true;
					
					// Go through the drugs.
					for (int i=0; i<nD; i++) {
						
						String mycode = student.get(i+1);
						
						// First thing is that it needs to be a substring.
						if (!drugs[i].contains(mycode))
							ok = false;
						
						boolean foundcode = false;
						
						// Go through the real codes to see which one theirs is.
						for (int j=0; j<nC; j++) {
							
							// We found it.
							if (codes[j].equals(mycode)) {
								foundcode = true;
								
								// If they used it before that's bad.
								if (usedcodes[j]) ok = false;
								
								// We're good; just mark this one as used.
								else usedcodes[j] = true;
							}
						}
						
						// If they listed a substring but it's not a valid code, we're not good.
						if (!foundcode) ok = false;
					}
					
					// If we make it here, task 2 was completed correctly.
					if (ok) score2 = 2;
				}
			}
			
			// Only tried task 1 and got it.
			else if (student.size() >= 1 && student.get(0).equals("yes"))
				score1 = 2;
			
			// Get total.
			int total = score1 + score2 + score3;
			
			// Print results.
			System.out.println("Task 1 score = "+score1+" Task 2 score = "+score2+" Task 3 score = "+score3);
			System.out.println("Total score = "+total);
		}
	}
}