{$apptype console}
uses
  testlib, SysUtils;

type
  int = longint;

var
  ins, goods, s : string;

function count(s : string) : int;
var
  min, max : char;
  i : int;
begin
  min := 'z';
  max := 'a';
  for i := 1 to length(s) do begin
    if (s[i] <= 'z') and (s[i] > max) then
      max := s[i];
    if (s[i] >= 'a') and (s[i] < min) then
      min := s[i];
  end;
  count := ord(max) - ord(min);
end;

var
  l : array [1..200001] of int;

procedure preKMP(p : string);
var
  i, j, m : int;
begin
  m := length(p);
  l[1] := 0;
  j := 0;
  for i := 2 to m do begin
    while ((j > 0) and (p[i] <> p[j + 1])) do
      j := l[j];
    if (p[i] = p[j + 1]) then
      l[i] := j + 1
    else
      l[i] := 0;
  end;
end; 

function KMP(t, p : string) : boolean;
var
  n, m, i, j : int;
begin
  n := length(t);
  m := length(p);
  preKMP(p);
  j := 0;
  result := false;
  for i := 1 to m do begin
    while ((j > 0) and (t[j + 1] <> p[i])) do
      j := l[j];
    if (p[i] = t[j + 1]) then
      j := j + 1;
    if (j = n) then
      result := true;
  end;
  
end;

begin
  ins := inf.readword(blanks, blanks);
  goods := ans.readword(blanks, blanks);
  s := ouf.readword(blanks, blanks);

  if not(ouf.seekeof) then
    quit(_pe, 'Extra information in output');
  if (length(s) <> length(goods)) then
    quit(_wa, 'Wrong length of word');
  if (count(s) <> count(goods)) then
    quit(_wa, 'Wrong quality of word');
  if (not KMP(s, ins) and (s <> ins)) then
    quit(_wa, 'Wrong word');

  quit(_ok, 'Quality is ' + IntToStr(count(goods)));
end.