program domino_kauliukai;
  { 66 u‘davinys }

  type domino = array [0..6, 0..6] of integer;
       vaibe = set of 0..6;
       v_laipsniai = array [0..6] of integer;
  procedure eiti (v : integer; { virž–n‚, nuo kurios pradedame eiti }
                  dm : domino;
                  var aibe : vaibe);
    var i : integer;
  begin
    aibe := aibe + [v];
    for i := 0 to 6 do
      if (dm[i, v]  <> 0) and not (i in aibe)
         then eiti (i, dm, aibe)
  end;

  function rasti (dm : domino) : boolean;
    var s : v_laipsniai;  { aku‡i— pasikartojim— skai‡ius }
                                      { arba virž–ni— laipsniai }
       aibe : vaibe; { virž–ni—, pasiekiam— iž nulin‚s virž–n‚s, aib‚ }
       nel, i, j : integer;
  begin
    { rasime grafo virž–ni— laipsnius }
    for i := 0 to 6 do
      s[i] := 0;
    for  i := 0 to 6 do
      for j :=  i to  6 do
        begin
          s[i] := s[i] + dm[i, j];
          s[j] := s[j] + dm[i, j];
        end;
     { rasime nelygini— virž–ni— skai‡i— }
     nel := 0;
     for i := 0 to 6 do
       nel := nel + s[i] mod 2;
     { tikrinsime, ar grafas jungus }
     aibe := [];
     {  aibŠ trauksime izoliuotas virž–nes }
     { j— apeiti nereikia }
     for i := 0 to 6 do
       if s[i] = 0
          then aibe := aibe + [i];
     eiti (0, dm, aibe); { rasime visas virž–nes, kurias galime }
               { pasiekti iž nulin‚s }
     if ((nel = 2) or (nel = 0)) and (aibe = [0..6])
        then rasti := true
        else rasti := false;
  end;

{----------------------------------------------------------}
  var f : text;
      i, j, k1, k2, sk : integer;
      galima : boolean;
      dm : domino;
begin
  assign (f,'domino.dat');
  reset (f);
  { inicializuojamas domino kauliuk— masyvas }
  for i := 1 to 6 do
    for j := 1 to 6 do
        dm[i, j] := 0;
  while not eof(f) do
    begin
      readln (f, k1, k2, sk);
      dm [k1, k2] := sk;
      dm [k2, k1] := sk;
    end;
  close (f);

  galima := rasti (dm);
  if galima
     then writeln ('GALIMA')
     else writeln ('NEGALIMA')
end.