#include <stdio.h>
#include <string.h>
int main()
{
int a[4][1000]; // A/C/G/T在每列中出現的次數
char c, x;
char bas[4] = { 'A', 'C', 'G', 'T' };
int T, m, n, i, j, k, dist;
scanf("%d", &T);
while (T--)
{
scanf("%d %d\n", &m, &n);
memset(a, 0, sizeof(a));
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
c = getchar();
if (c == 'A')
++a[0][j];
else if (c == 'C')
++a[1][j];
else if (c == 'G')
++a[2][j];
else
++a[3][j];
}
getchar();
}
dist = 0;
for (j = 0; j < n; ++j)
{
k = -1;
for (i = 0; i < 4; ++i)
{
if (a[i][j] > k)
{
k = a[i][j];
x = bas[i];
}
}
for (i = 0; i < 4; ++i)
{
if (bas[i] != x)
dist += a[i][j];
}
putchar(x);
}
printf("\n%d\n", dist);
}
return 0;
}