
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

bool solve(string[][char] words, char first, char suffix, uint rest) {
  if (rest == 0) {return first == suffix;}
  if (!(suffix in words) || words[suffix] == []) return false;
  foreach(uint index, string word; words[suffix]) {
    auto w = words.dup;
    w[suffix] = remove(w[suffix], index);
    if (solve(w, first, word[$ - 1], rest - 1)) return true;
  }
  return false;
}

void main() {
  while(true) {
    string[][char] words;
    int n = readln.chomp.to!(int);
    if (n == 0) break;
    foreach(t; 0..(n  - 1)) {
      auto line = readln.chomp;
      words[line[0]] ~= line;
    }
    auto line = readln.chomp;
    writeln(solve(words, line[0], line[$ - 1], n - 1) ? "OK" : "NG");
  }
}