### constant

N = 1000
G = 3
GG = G * G

BTNS = ["ABC", "DEF", "GHI"]
DXYS = [[1, 0], [0, 1], [-1, 0], [0, -1]]

### main

nbrs = Array.new(GG){Array.new(GG){false}}

for y0 in (0...G)
  for x0 in (0...G)
    c0 = BTNS[y0][x0].ord - 'A'.ord

    DXYS.each do |dx, dy|
      x = x0 + dx
      y = y0 + dy
      if x >= 0 && x < G && y >= 0 && y < G
        c1 = BTNS[y][x].ord - 'A'.ord
        nbrs[c0][c1] = nbrs[c1][c0] = true
      end
    end
  end
end

while line = gets
  str = line.strip

  cf = true
  prvc = str[0].ord - 'A'.ord

  for i in (1...str.length)
    c = str[i].ord - 'A'.ord
    if ! nbrs[prvc][c]
      cf = false
      break
    end
    prvc = c
  end

  puts str if cf
end