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

public class coincidence_ats_dumb implements Runnable {
	public static void main(String[] args) {
		new Thread(new coincidence_ats_dumb()).start();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public class Contestant {
		String name;
		String ip;
		int rating;
		int place;
		int level;
		int[] results;
		int count;

		public Contestant(String name, int rating) {
			this.name = name;
			this.rating = rating;
			this.level = 0;
			this.ip = "";
			count = 0;
			results = new int[m];
			Arrays.fill(results, -1);
		}

		public void update(int delta) {
			rating += delta;
			rating = Math.min(rating, 10);
			rating = Math.max(rating, 0);
		}

		public void checkIP(String ip) {
			assert (this.ip.equals("") || this.ip.equals(ip));
			this.ip = ip;
		}
	}

	int n;
	int m;

	public void solve() throws IOException {
		n = nextInt();
		m = nextInt();
		HashMap<String, Contestant> users = new HashMap<String, Contestant>();
		ArrayList<String> names = new ArrayList<String>();
		for (int i = 0; i < n; i++) {
			String name = nextToken();
			int rating = nextInt();
			Contestant nc = new Contestant(name, rating);
			nc.place = i;
			names.add(name);
			users.put(name, nc);
		}
		boolean[][] sus = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(sus[i], true);
		}
		for (int i = 0; i < m; i++) {
			int k = nextInt();
			ArrayList<Integer> contestants = new ArrayList<Integer>();
			for (int j = 0; j < k; j++) {
				String curName = nextToken();
				int curRes = nextInt();
				int curDelta = nextInt();
				String ip = nextToken();

				users.get(curName).update(curDelta);
				users.get(curName).results[i] = curRes;
				users.get(curName).count++;
				users.get(curName).checkIP(ip);

				contestants.add(users.get(curName).place);
			}
			for (int j = 0; j < k; j++) {
				for (int l = 0; l < k; l++) {
					sus[contestants.get(j)][contestants.get(l)] = false;
					sus[contestants.get(l)][contestants.get(j)] = false;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			if (users.get(names.get(i)).count == 0) {
				users.get(names.get(i)).level = 0;
				continue;
			}
			users.get(names.get(i)).level = 10;
			for (int j = 0; j < m; j++) {
				if (users.get(names.get(i)).results[j] == -1) {
					continue;
				}
				for (int k = 0; k < n; k++) {
					if (users.get(names.get(k)).results[j] > users.get(names
							.get(i)).results[j]
							&& users.get(names.get(k)).rating < users.get(names
									.get(i)).level) {
						users.get(names.get(i)).level = Math.max(0,
								users.get(names.get(k)).rating);
					}
				}
			}
		}

		boolean[] bad = new boolean[n];
		Arrays.fill(bad, false);

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (sus[i][j]
						&& users.get(names.get(i)).rating > users.get(names
								.get(j)).rating
						&& users.get(names.get(i)).rating == users.get(names
								.get(j)).level
						&& users.get(names.get(i)).ip.equals(users.get(names
								.get(j)).ip)) {
					// System.err.println(names.get(i) + " " + names.get(j));
					bad[i] = true;
				}
			}
		}
		ArrayList<String> ans = new ArrayList<String>();
		for (int i = 0; i < n; i++) {
			if (bad[i]) {
				ans.add(names.get(i));
			}
		}
		Collections.sort(ans);
		out.println(ans.size());
		for (int i = 0; i < ans.size(); i++) {
			out.println(ans.get(i));
		}
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader("coincidence.in"));
			out = new PrintWriter("coincidence.out");

			solve();

			out.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
