#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<ll, ll> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell 998244353LL
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
     if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int M = 1005;
const int N = 1005;
const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll euclid(ll x,ll y,ll a,ll b)
{
  return (a-x)*(a-x)+(b-y)*(b-y);
}
ll mod = 998244353LL;
ll add(ll a,ll b)
{
  a%=mod;
  b%=mod;
  return (a+b)%mod;
}

ll sub(ll a,ll b)
{
  a%=mod;
  b%=mod;
  return (a-b+mod)%mod;
}
ll multiply(ll a,ll b)
{
  a%=mod;
  b%=mod;
  return (a*b)%mod;
}
ll inv(ll a)
{
  a = sub(a,0);
  return power(a,mod-2,mod);
}
//Constants // 
char a[31][31];
ll vis[31][31];
string ans;
ll r,c;
bool valid(ll x,ll y)
{
  ll i,j;
  char ch = a[x][y];
  for(i=r;i>=1;i--)
  {
    for(j=1;j<=c;j++)
    {
      if(a[i][j]==ch)
      {
        if(i==r || vis[i+1][j])
          vis[i][j]=1;
        else
          return false;
      }
    }
  }
  return true;
}
void Fill(ll x,ll y,ll val)
{
  char ch = a[x][y];
  ll i,j;
  for(i=r;i>=1;i--)
  {
    for(j=1;j<=c;j++)
    {
      if(a[i][j]==ch)
        vis[i][j] = val;
    }
  }
}
bool recur()
{
  ll i,j;
  for(i=r;i>=1;i--)
  {
    for(j=1;j<=c;j++)
    {
      if(!vis[i][j])
      {
        trace2(i,j);
        if(valid(i,j))
        {
          trace2(i,j);
          Fill(i,j,1);
          ans.pb(a[i][j]);
          trace(ans);
          if(recur())
            return true;
          Fill(i,j,0);
          ans.pop_back();
        }
        else
          Fill(i,j,0);
      }
    }
  }
  return false;
}
void solve()
{
  cin>>r>>c;
  ll i,j;
  rep(i,1,r+1)
    rep(j,1,c+1)
      cin>>a[i][j];
  memset(vis,0,sizeof(vis));    
  ans = "";    
  if(recur())
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
}
int main()
{ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t,i=1;
  // t=1;
  cin>>t;
  // preprocess();
  while(i<=t)
  {
    cout<<"Case #"+to_string(i)+": ";
    solve();
    i++;
  }
  return 0;
}