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

void main() {
  while(true) {
    char[] suffix, prefix;
    bool ans = true;
    int n = readln.chomp.strip.to!(int);
    if (n == 0) break;
    foreach(i; 0..n) {
      string line = readln.chomp;
      prefix ~= line[0];
      suffix ~= line[$ - 1];
      if (line[0] == line[$ - 1]) {ans = false;}
    }
    if (!ans) {writeln("NG"); continue;}
    writeln(suffix.sort == prefix.sort ? "OK" : "NG");
  }
}