### subroutines

def transform(name)
  trans = {}
  len = name.length

  # 1. Delete
  for i in (0...len)
    v = name.clone
    v[i] = ''
    trans[v] = true
  end

  # 2. Insert
  for i in (0..len)
    for ch in ('a'..'z')
      v = name.clone
      v[i, 0] = ch
      trans[v] = true
    end
  end

  # 3. Replace
  for i in (0...len)
    for ch in ('a'..'z')
      v = name.clone
      v[i] = ch
      trans[v] = true
    end
  end

  # 4. Swap
  (0...len).each_cons(2) do |i, j|
    v = name.clone
    v[i] = name[j]
    v[j] = name[i]
    trans[v] = true
  end

  trans
end

### main

loop do
  n = gets.to_i
  break if n == 0

  d = gets.to_i

  names = []
  nmthash = {}
  nmts = {}

  n.times do
    name = gets.strip
    names << name
    trans = transform(name)
    nmthash[name] = trans
    nmts[name] = trans.keys
  end

  confs = []

  for i in (0...n)
    nmi = names[i]
    nmithash = nmthash[nmi]

    for j in ((i + 1)...n)
      nmj = names[j]

      if nmithash[nmj]
        confs << [nmi, nmj].sort
        next
      end
      next if d < 2

      nmts[nmj].each do |nmtj|
        if nmithash[nmtj]
          confs << [nmi, nmj].sort
          break
        end
      end
    end
  end

  confs.sort.each do |nm0, nm1|
    puts [nm0, nm1].join(',')
  end
  puts confs.length
end