import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.Writer;
import java.math.BigInteger;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class eve_egor {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("eve.in");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("eve.out");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		Eve solver = new Eve();
		solver.solve(1, in, out);
		out.close();
	}
}

class Eve {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int initialCount = in.readInt();
		for (int i = 0; i < initialCount; i++)
			in.readCharacter();
		int eventCount = in.readInt();
		int[] id = new int[eventCount];
		int birthCount = 0;
		for (int i = 0; i < eventCount; i++) {
			id[i] = in.readInt();
			if (id[i] < 0)
				continue;
			id[i] = in.readInt() - 1;
			in.readCharacter();
			birthCount++;
		}
		boolean[] alive = new boolean[initialCount + birthCount];
		Arrays.fill(alive, true);
		for (int i : id) {
			if (i < 0)
				alive[-i - 1] = false;
		}
		int[] parent = new int[initialCount + birthCount];
		for (int i = 0; i < initialCount; i++)
			parent[i] = i;
		int index = initialCount;
		for (int i : id) {
			if (i >= 0)
				parent[index++] = parent[i];
		}
		boolean[] isAliveFamily = new boolean[initialCount];
		for (int i = 0; i < initialCount + birthCount; i++) {
			if (alive[i])
				isAliveFamily[parent[i]] = true;
		}
		int[] dna = new int[initialCount];
		for (int i = 0; i < initialCount; i++)
			dna[i] = -i;
		int measureCount = in.readInt();
		for (int i = 0; i < measureCount; i++) {
			int curID = in.readInt() - 1;
			dna[parent[curID]] = in.readInt();
		}
		Set<Integer> dnas = new HashSet<Integer>();
		for (int i = 0; i < initialCount; i++) {
			if (isAliveFamily[i])
				dnas.add(dna[i]);
		}
		if (dnas.size() == 1) {
			out.printLine("YES");
			return;
		}
		int positiveCount = 0;
		for (int i : dnas) {
			if (i > 0)
				positiveCount++;
		}
		if (positiveCount <= 1)
			out.printLine("POSSIBLY");
		else
			out.printLine("NO");
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

