// Josh Michalczak

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

public class vocab {
	public static void main(String arg[]) {
		vocab app = new vocab();
		app.run();
	}
	
	int N = 602;
	int capacity[][] = new int[N][N];
	int source = 0;
	int sink = 1;
	
	ArrayList<String> dictionary = new ArrayList<String>();
	HashMap<String, Integer> map = new HashMap<String, Integer>();
	
	public void run() {
		Scanner in = new Scanner(System.in);
		in.useDelimiter("[^a-zA-Z0-9]+");
		
		//Initialize connections between source and dictionary
		for(int i = 0; i < 100; ++i) {
			capacity[source][i + 2] = 1;
		}
		//Initialize connections between sentence words and sink
		for(int i = 0; i < 500; ++i) {
			capacity[i + 102][sink] = 1;
		}
		
		//Read in dictionary
		int dictionarySize = in.nextInt();
		for(int i = 0; i < dictionarySize; ++i) {
			String word = in.next().toLowerCase();
			if(map.get(word) == null) { //not sure if dictionary repeats words?
				dictionary.add(word);
				map.put(word, i);
			}
		}
		dictionarySize = map.size();
		
		//Read in sentences
		int sentenceCount = in.nextInt();
		in.nextLine(); //hack to get nextline to work
		
		for(int s = 0; s < sentenceCount; ++s) {
			Scanner parser = new Scanner(in.nextLine());
			parser.useDelimiter("[^a-zA-Z]+");	//delimits on any non-letter character
			
			
			int currentWord = 102;
			
			// Read in each word, setting up a link between the word in the message
			// and the word in the dictionary in the flow network.
			while(parser.hasNext()) {
				String word = parser.next().toLowerCase();
				for(String dict : dictionary) {
					if(wordsMatch(dict, word)) {
						capacity[map.get(dict) + 2][currentWord] = 1;
					}
				}
				currentWord++;
			}
			
			// If the most flow is less than the number of words in the dictionary,
			// there's no way to map ALL the words in the list to the sentence.
			if(maxflow() < dictionarySize) {
				System.out.println("NOT FLAGGED");
			} else {
				System.out.println("FLAGGED");
			}
			
			//reset the capacities between dictionary and sentence words
			for(int i = 2; i < 2+dictionarySize; ++i) {
				for(int j = 102; j < currentWord; ++j) {
					capacity[i][j] = 0;
				}
			}
		}
	}
	
	// Returns true iff the difference between word1 and word2 is
	// at most 1 character.
	public boolean wordsMatch(String word1, String word2) {
		if(word1.length() != word2.length()) return false;
		
		boolean foundDiff = false;
		for(int i = 0; i < word1.length(); ++i) {
			if(word1.charAt(i) != word2.charAt(i)) {
				if(foundDiff) return false;
				foundDiff = true;
			}
		}
		return true;
	}
	
	// Hack pack code that solves Max Flow.
	public int maxflow() {
		
		// All of our data structures.
		int flowGraph[][] = new int[N][N];
		int previous[] = new int[N];
		Queue<Integer> que = new ArrayDeque<Integer>();
		int pathFlow[] = new int[N];
		int current, i, flow;
		
		// Trivial case.
		if(source == sink) return Integer.MAX_VALUE;
		
		for(;;) {
			Arrays.fill(previous, -1);
			pathFlow[source] = Integer.MAX_VALUE;
			que.clear();
			que.add(source);
		
			// Find an augmenting path - the previous array stores the path.
			while(!que.isEmpty() && previous[sink] < 0) {
				current = que.poll();
				for(i = 0; i < N; i++) {
					flow = capacity[current][i] - flowGraph[current][i];
					if((previous[i] < 0) && (flow > 0)) {
						que.add(i);
						previous[i] = current;
						pathFlow[i] = Math.min(pathFlow[current], flow);
					}
				}
			}
			if(previous[sink] < 0) break;
			
			// Adjust the flows for this augmenting path we just found.
			for(i = sink; i != source; i = previous[i]) {
				flowGraph[previous[i]][i] += pathFlow[sink];
				flowGraph[i][previous[i]] -= pathFlow[sink];
			}
		}
		
		// The flow is just all the flow coming out of the sink!
		flow = 0;
		for(i = 0; i < N; flow += flowGraph[i++][sink]);
		return flow;
	}
}