// Problem   Phylogenetic Trees Inherited
// Algorithm Dynamic Programming
// Runtime   O(n * l)
// Author    Walter Guttmann
// Date      24.06.2000

#include <algorithm>
#include <fstream>
#include <iostream>
#define in cin

using namespace std;

const int OO = 1000000000;

char seq[1024][1024];
int cost[2048][32];

main ()
{
  int n, l;
  while (in >> n >> l)
  {
    if (n == 0 && l == 0) break;
    for (int k=0 ; k<n ; k++)
      in >> seq[k];
    int total = 0;
    for (int i=0 ; i<l ; i++)
    {
      fill_n (cost[0], 2*n*32, OO);
      for (int k=0 ; k<n ; k++)
        cost[n+k][seq[k][i]-'A'] = 0;
      for (int k=n-1 ; k>0 ; k--)
        for (int d=0 ; d<32 ; d++) if (cost[2*k][d] < OO)
          for (int e=0 ; e<32 ; e++) if (cost[2*k+1][e] < OO)
          {
            int c = cost[2*k][d] + cost[2*k+1][e] + (d==e ? 0 : 1);
            cost[k][d] = min (cost[k][d], c);
            cost[k][e] = min (cost[k][e], c);
          }
      int *mini = min_element (cost[1], cost[1]+32);
      cout << (char) ('A' + (mini - cost[1]));
      total += *mini;
    }
    cout << ' ' << total << endl;
  }
  return 0;
}

