program main;
const alpha=['А'..'Я', 'а'..'п', 'р'..'я', 
            '.', ',', '-', ':', ';', '?', 
            '!', '"'];
type T=array[1..100] of string;
type A=set of char;
var i, j, k: integer;
    found, s, temp: string; 
    n: integer; {Количество прочитанных слов}
    words: T; {Массив слов}
    first: A; {Множество букв первого слова}
    flag: boolean;
    

procedure GetWords(s: string; var a: T; var n: Integer);
var _word: String;
    i: Integer;
begin
  i:=1;
  n:=0;
  s:=s+ ' ';
  while i<length(s) do
    if s[i] in alpha then begin
      _word:='';
      while (s[i] in alpha) and (i<length(s)) do begin
        _word:=_word+s[i];
        inc(i);
      end;
      if _word <> ' ' then begin
        inc(n);
        a[n]:=_word;
      end;
    end
    else inc(i);
    a[n]:=a[n]+s[i];
end;

function up(s: string): string;
var i: Integer;
    s1: string;
begin
  s1:='';
  for i:=1 to length(s) do
    case s[i] of
      'А'..'Я' : s1:=s1+s[i];
      'а'..'п': s1:=s1+chr(ord('А')+ord(s[i])-ord('а'));
      'р'..'я': s1:=s1+chr(ord('П')+ord(s[i])-ord('п'));
    end;
  up:=s1;
end;

begin
  assign(input, 'input.txt');
  reset(input);
  assign(output, 'output.txt');
  rewrite(output);
  
  flag:=false;
  while not eof(input) do begin
    readln(input, s);
    GetWords(s, words, n);
    if not flag then
      for i:=1 to length(words[1]) do
        include(first, words[1][i]);
    flag:=true;
      
    for i:=1 to n do begin
      j:=1;
      k:=0; {Количество букв в текущем слове, содержащихся также в первом слове}
      temp:='(';
      for j:=1 to length(words[i]) do begin
        if words[i][j] in first then begin
          temp:=temp+words[i][j];
          inc(k);
        end;
      end;
      if k>=3 then begin
        temp:=temp+')';
        write(output, up(words[i]), ' ', temp, ' ');
      end
      else
        write(output,words[i], ' ');
    end;
  end;  
  close(input);
  close(output);
end.