#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

char ans[55 * 55];
int t = 0;
int len = -1;

char str[55 * 55];
int w = 0;
pair<int, int>  p[55 * 55];
int pt = 0;
set<pair<int, int> > q;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			w = 0;
			pt = 0;
			p[pt++] = mp(sx, sy);
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, pt)
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					q.clear();
            					q.insert(mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q.insert(mp(p[o].x, p[o].y));
                            }
            			}
            	str[w++] = (char)mm;
            	pt = 0;
            	for(set<pair<int, int> >::iterator iter = q.begin(); iter != q.end(); ++iter) p[pt++] = *(iter);
            	q.clear();
            }

            if(len == -1 || len > d[sx][sy])
			{
				len = d[sx][sy];
		        rep(i, w) ans[i] = str[i];
		    }
			else
			{
				bool ok = false;
				rep(i, w)
				{
					if(ans[i] > str[i])
					{
						ok = true;
						break;
					}
					else if(ans[i] < str[i])
					{
						break;
					}
				}
				if(ok)
				{
					rep(i, w) ans[i] = str[i];
				}
			}
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else
	{
		rep(i, len - 1) printf("%c", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

string ans;
int len = -1;

vector<pair<int, int> > p;
vector<pair<int, int> > q;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			string str;
			p.clear();
			q.clear();
			p.pb(mp(sx, sy));
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, p.size())
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					q.clear();
            					q.pb(mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q.pb(mp(p[o].x, p[o].y));
                            }
            			}
            	str.pb((char)mm);
            	p.clear();
               	rep(i, q.size()) p.pb(q[i]);
               	q.clear();
			}
			if(len == -1 || (len > d[sx][sy] || str < ans)) ans = str, len = d[sx][sy];
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else printf("%s", ans.c_str());

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

char ans[55 * 55];
int t = 0;
int len = -1;

char str[55 * 55];
int w = 0;
pair<int, int>  p[55 * 55];
int pt = 0;
set<pair<int, int> > q;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			w = 0;
			pt = 0;
			p[pt++] = mp(sx, sy);
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, pt)
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					q.clear();
            					q.insert(mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q.insert(mp(p[o].x, p[o].y));
                            }
            			}
            	str[w++] = (char)mm;
            	pt = 0;
            	for(set<pair<int, int> >::iterator iter = q.begin(); iter != q.end(); ++iter) p[pt++] = *(iter);
            	q.clear();
            }
            if(len == -1 || len > d[sx][sy])
			{
				len = d[sx][sy];
		        rep(i, w) ans[i] = str[i];
			}
			bool ok = false;
			rep(i, w)
			{
				if(ans[i] > str[i])
				{
					ok = true;
					break;
				}
				else if(ans[i] < str[i]);
				{
					break;
				}
			}
			if(ok)
			{
				len = d[sx][sy];
		        rep(i, len) ans[i] = str[i];
			}
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else
	{
		rep(i, len - 1) printf("%c", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

string ans;
int len = -1;

string str;
vector<pair<int, int> > p;
vector<pair<int, int> > q;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			str.clear();
			p.clear();
			q.clear();
			p.pb(mp(sx, sy));
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, p.size())
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					q.clear();
            					q.pb(mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q.pb(mp(p[o].x, p[o].y));
                            }
            			}
            	str.pb((char)mm);
            	p.clear();
               	rep(i, q.size()) p.pb(q[i]);
               	q.clear();
			}
			if(len == -1 || (len > d[sx][sy] || str < ans)) ans = str, len = d[sx][sy];
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else printf("%s", ans.c_str());

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

char ans[55 * 55];
int t = 0;
int len = -1;

char str[55 * 55];
int w = 0;
pair<int, int>  p[55 * 55];
int pt = 0;
pair<int, int>  q[55 * 55];
int qt = 0;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			w = 0;
			pt = 0;
			qt = 0;
			p[pt++] = mp(sx, sy);
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, pt)
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					qt = 0;
            					q[qt++] = (mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q[qt++] = (mp(p[o].x, p[o].y));
                            }
            			}
            	str[w++] = (char)mm;
            	pt = 0;
            	rep(i, qt) p[pt++] = (q[i]);
            	qt = 0;
            }
			if(len == -1 || len > d[sx][sy])
			{
				len = d[sx][sy];
		        rep(i, w) ans[i] = str[i];
			}
			bool ok = false;
			rep(i, w)
			{
				if(ans[i] > str[i])
				{
					ok = true;
					break;
				}
				else if(ans[i] < str[i]);
				{
					break;
				}
			}
			if(ok)
			{
				len = d[sx][sy];
		        rep(i, len) ans[i] = str[i];
			}
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else
	{
		rep(i, len - 1) printf("%c", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <string.h>

#define fori(i, l, r) for(int i = l; i < (int)(r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define sz(x) (int)(x).size()
#define TASKNAME ""
typedef long long int64;
typedef long double real;

const int magicconst = 73743071;

using namespace std;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int sx, sy, tx, ty;
int n, m;
int d[55][55];
char u[55][55];
bool b[255];

bool crt(int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < m && b[u[x][y] - 'a'];
}

inline void bfs()
{
	queue<pair<int, int> > q;
	q.push(mp(tx, ty));
	memset(d, -1, sizeof d);
	d[tx][ty] = 0;

	while(!q.empty())
	{
		pair<int, int> temp = q.front();
		q.pop();
		rep(i, 4)
			if(crt(temp.x + dx[i], temp.y + dy[i]) && d[temp.x + dx[i]][temp.y + dy[i]] == -1)
			{
				d[temp.x + dx[i]][temp.y + dy[i]] = d[temp.x][temp.y] + 1;
				q.push(mp(temp.x + dx[i], temp.y + dy[i]));
			}
	}
	/*rep(i, 26) if(b[i]) printf("%c ", i + 'a');
	printf("\n");
	rep(i, n) rep(j, m) printf("%d%c", d[i][j], " \n"[j == m - 1]);
	printf("---------\n");
	*/
}

string ans;
int len = -1;

int go(int v, int k)
{
	if(k == 0)
	{
		bfs();

		if(d[sx][sy] != -1 && (len == -1 || d[sx][sy] <= len))
		{
			vector<pair<int, int> > p;
			vector<pair<int, int> > q;
            string str;
			p.pb(mp(sx, sy));
			rep(j, d[sx][sy] - 1)
            {
            	int mm = 100500;
            	rep(o, p.size())
            		rep(i, 4)
            			if(crt(p[o].x + dx[i], p[o].y + dy[i]) && d[p[o].x + dx[i]][p[o].y + dy[i]] == d[p[o].x][p[o].y] - 1)
            			{
            				if(u[p[o].x + dx[i]][p[o].y + dy[i]] < mm)
            				{
            					q.clear();
            					q.pb(mp(p[o].x + dx[i], p[o].y + dy[i]));
            					mm = u[p[o].x + dx[i]][p[o].y + dy[i]];
            				}
            				else if(u[p[o].x + dx[i]][p[o].y + dy[i]] == mm)
            				{
            					q.pb(mp(p[o].x, p[o].y));
                            }
            			}
            	str.pb((char)mm);
            	p.clear();
               	rep(i, q.size()) p.pb(q[i]);
               	q.clear();
			}
			if(len == -1 || (len > d[sx][sy] || str < ans)) ans = str, len = d[sx][sy];
		}
	}
	else
	{
		fori(i, v + 1, 26)
		{
			b[i] = 1;
			go(i, k - 1);
			b[i] = 0;
	   	}
	}
}

int main()
{
//	freopen(TASKNAME ".in", "rt", stdin);
//	freopen(TASKNAME ".out", "wt", stdout);

	int k;
	scanf("%d%d%d\n", &n, &m, &k);

	rep(i, n)
	{
		rep(j, m)
		{
			scanf("%c", &u[i][j]);
			if(u[i][j] == 'S') sx = i, sy = j;
			if(u[i][j] == 'T') tx = i, ty = j;
		}
		scanf("\n");
	}
	memset(b, 0, sizeof b);
	b['S' - 'a'] = 1;
	b['T' - 'a'] = 1;
	go(-1, k);
	if(len == -1) printf("-1");
	else printf("%s", ans.c_str());

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

const int maxN= 50+5;
const int INF = 1000*1000*1000;

bool flag[30];
char mat [maxN][maxN];
int n,m,k,res=INF;
int dis[maxN][maxN];
int dp [maxN][maxN];
vector <char> Q;
pii beg, fin;
pii par[maxN][maxN];
string ans;

int move[4][2]= {{-1,0}, {1,0}, {0,-1}, {0,1}};

inline bool valid (int x, int y){
    return (x*y!=0) && (x<=n) && (y<=m);
}

inline bool cmp (const pii &a1, const pii &a2){
    return dp[a1.first][a1.second] < dp[a2.first][a2.second];
}

inline void setPath (){

    for (int i=1;i<=n;i++)
        memset (dis[i], -1, sizeof dis[i]);

    vector <pii> qu;

    qu.push_back (fin);

    dis[fin.first][fin.second]= 0;
    dp [fin.first][fin.second]= 0;

    for (int i=0; i<(int)qu.size();){

        int j=i;

        while (j<(int)qu.size()){
            if (dis[qu[j].first][qu[j].second]==dis[qu[i].first][qu[i].second])
                j++;
            else
                break;
        }

        sort (qu.begin()+i, qu.begin()+j, cmp);

        while (i<j){

            pii now= qu[i];

            for (int z=0;z<4;z++){

                int x= now.first  + move[z][0];
                int y= now.second + move[z][1];

                if (valid(x,y) && dis[x][y]==-1 && (mat[x][y]=='S' || flag[mat[x][y]-'a'])){
                    dis[x][y]= dis[now.first][now.second] + 1;
                    par[x][y]= now;
                    dp [x][y]= 2600*(mat[x][y]-'a') + dp[now.first][now.second];
                    qu.push_back (pii(x,y));
                }
            }

            i++;
        }
    }

    if (dis[beg.first][beg.second]==-1 || (res<dis[beg.first][beg.second]))
        return;

    pii tmp= beg;
    string ret="";

    while (tmp!=fin){
        if (tmp!=beg)
            ret+= mat[tmp.first][tmp.second];
        tmp= par[tmp.first][tmp.second];
    }

    if ((int)ret.size()+1<res || ((int)ret.size()+1==res && ret<ans)){
        res= ret.size() + 1;
        ans= ret;
    }
}

inline void check (int len){

    if (len==(int)Q.size()){

        memset (flag, false, sizeof flag);

        for (int i=0;i<(int)Q.size();i++)
            flag[Q[i]-'a']= true;

        setPath();

        return;
    }

    for (char i= (Q.empty()) ? 'a' : Q.back()+1 ; i<='z' ; i++){
        Q.push_back (i);
        check (len);
        Q.pop_back();
    }
}

int main(){

    scanf ("%d%d%d", &n, &m, &k);

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            scanf (" %c", &mat[i][j]);

            if (mat[i][j]=='S')
                beg= pii(i,j);

            else if (mat[i][j]=='T')
                fin= pii(i,j);
        }

    for (int i=0;i<4;i++){

        int x= beg.first  + move[i][0];
        int y= beg.second + move[i][1];

        if (valid(x,y) && mat[x][y]=='T'){
            printf ("\n");
            return 0;
        }
    }

    check (k);

    if (res==INF){
        printf ("-1\n");
        return 0;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int,int> pii;

const int maxN= 50+5;
const int INF = 1000*1000*1000;

char mat [maxN][maxN];
bool mark[maxN][maxN];
bool flag[30];

int  n,m,k,res=INF;

int  dis [maxN][maxN];
vector <char> Q;

pii beg, fin;

string ans;

int move[4][2]= {{-1,0}, {1,0}, {0,-1}, {0,1}};

inline bool valid (int x, int y){
    return (x*y!=0) && (x<=n) && (y<=m);
}

inline string setPath (){

    for (int i=1;i<=n;i++)
        memset (mark[i], false, sizeof mark[i]);

    queue <pii> qu;

    qu.push (fin);
    mark[fin.first][fin.second]= true;

    while (!qu.empty() && !mark[beg.first][beg.second]){

        pii top= qu.front(); qu.pop();

        for (int i=0;i<4;i++){

            int x= top.first  + move[i][0];
            int y= top.second + move[i][1];

            if (valid(x,y) && (mat[x][y]=='S') || (!mark[x][y] && dis[x][y]==dis[top.first][top.second]-1)){
                mark [x][y]= true;
                qu.push (pii(x,y));
            }
        }
    }

    string ret= "";

    pii now= beg;

    while (now!=fin){

        if (now!=beg)
            ret+= mat[now.first][now.second];

        char mini= 'z'+1;
        pii next;

        for (int i=0;i<4;i++){

            int x= now.first  + move[i][0];
            int y= now.second + move[i][1];

            if (valid(x,y) && mark[x][y] && dis[x][y]==dis[now.first][now.second]+1 && mat[x][y]<mini){
                mini= mat[x][y];
                next= pii(x,y);
            }
        }

        now= next;
    }

    return ret;
}

inline void bfs (){

    for (int i=1;i<=n;i++){
        memset (mark[i], false, sizeof mark[i]);
        memset (dis [i], -1, sizeof dis [i]);
    }

    queue <pii> qu;

    qu.push (beg);
    mark[beg.first][beg.second]= true;

    dis[beg.first][beg.second]= 0;

    while (!qu.empty() && !mark[fin.first][fin.second]){

        pii top= qu.front(); qu.pop();

        for (int i=0;i<4;i++){

            int x= top.first  + move[i][0];
            int y= top.second + move[i][1];

            if (valid (x,y) && !mark[x][y] && (mat[x][y]=='T' || flag[mat[x][y]-'a'])){
                mark [x][y]= true;
                dis  [x][y]= dis[top.first][top.second] + 1;
                qu.push (pii(x,y));
            }
        }
    }

    if (mark[fin.first][fin.second] && dis[fin.first][fin.second] <= res){

        string tmp= setPath();

        if (((int)tmp.size()+1) < res){
            res= tmp.size() + 1;
            ans= tmp;
        }

        else if (tmp < ans){
            ans= tmp;
        }
    }
}

inline void check (int len){

    if (len==(int)Q.size()){

        memset (flag, false, sizeof flag);

        for (int i=0;i<(int)Q.size();i++)
            flag[Q[i]-'a']= true;

        bfs ();

        return;
    }

    for (char i= (Q.empty()) ? 'a' : Q.back()+1 ; i<='z' ; i++){
        Q.push_back (i);
        check (len);
        Q.pop_back();
    }
}

int main(){

    scanf ("%d%d%d", &n, &m, &k);

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            scanf (" %c", &mat[i][j]);

            if (mat[i][j]=='S')
                beg= pii(i,j);

            else if (mat[i][j]=='T')
                fin= pii(i,j);
        }

    for (int i=0;i<4;i++){

        int x= beg.first  + move[i][0];
        int y= beg.second + move[i][1];

        if (valid(x,y) && mat[x][y]=='T'){
            printf ("\n");
            return 0;
        }
    }

    check (k);

    if (res==INF){
        printf ("-1\n");
        return 0;
    }

    else
        cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

const int maxN= 50+5;
const int INF = 1000*1000*1000;

char mat [maxN][maxN];
bool mark[maxN][maxN];
bool flag[30];

int  n,m,k,res=INF;

vector <char> Q;

pii beg, fin;

string ans;
string dp [maxN][maxN];

int move[4][2]= {{-1,0}, {1,0}, {0,-1}, {0,1}};

inline bool valid (int x, int y){
    return (x*y!=0) && (x<=n) && (y<=m);
}

inline void setPath (){

    for (int i=1;i<=n;i++)
        memset (mark[i], false, sizeof mark[i]);

    queue <pii> qu;

    qu.push (fin);

    mark[fin.first][fin.second]= true;
    dp  [fin.first][fin.second]= "";

    while (!qu.empty()){

        pii top= qu.front(); qu.pop();

        if (top==beg)
            break;

        for (int i=0;i<4;i++){

            int x= top.first  + move[i][0];
            int y= top.second + move[i][1];

            if (valid(x,y) && !mark[x][y] && (mat[x][y]=='S' || flag[mat[x][y]-'a'])){
                mark [x][y]= true;
                dp   [x][y]= mat[x][y] + dp[top.first][top.second];
                qu.push (pii(x,y));
            }

            else if (valid(x,y) && (mat[x][y]=='S' || (flag[mat[x][y]-'a'])))
                dp [x][y]= min (dp[x][y], mat[x][y] + dp[top.first][top.second]);
        }
    }

    if (!mark[beg.first][beg.second])
        return;

    if ((int)dp[beg.first][beg.second].size() < res){
        res= dp[beg.first][beg.second].size();
        ans= dp[beg.first][beg.second];
    }

    else if ((int)dp[beg.first][beg.second].size()==res)
        ans= min (ans, dp[beg.first][beg.second]);
}

inline void check (int len){

    if (len==(int)Q.size()){

        memset (flag, false, sizeof flag);

        for (int i=0;i<(int)Q.size();i++)
            flag[Q[i]-'a']= true;

        setPath();

        return;
    }

    for (char i= (Q.empty()) ? 'a' : Q.back()+1 ; i<='z' ; i++){
        Q.push_back (i);
        check (len);
        Q.pop_back();
    }
}

int main(){

    scanf ("%d%d%d", &n, &m, &k);

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            scanf (" %c", &mat[i][j]);

            if (mat[i][j]=='S')
                beg= pii(i,j);

            else if (mat[i][j]=='T')
                fin= pii(i,j);
        }

    for (int i=0;i<4;i++){

        int x= beg.first  + move[i][0];
        int y= beg.second + move[i][1];

        if (valid(x,y) && mat[x][y]=='T'){
            printf ("\n");
            return 0;
        }
    }

    check (k);

    if (res==INF){
        printf ("-1\n");
        return 0;
    }

    for (int i=1;i<(int)ans.size();i++)
        cout << ans[i];
    cout << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

const int maxN= 50+5;
const int INF = 1000*1000*1000;

char mat [maxN][maxN];
bool mark[maxN][maxN];
bool flag[30];

int  n,m,k,res=INF;

int  dis [maxN][maxN];
vector <char> Q;

pii beg, fin;

string ans;

int move[4][2]= {{-1,0}, {1,0}, {0,-1}, {0,1}};

inline bool valid (int x, int y){
    return (x*y!=0) && (x<=n) && (y<=m);
}

inline string setPath (){

    for (int i=1;i<=n;i++)
        memset (mark[i], false, sizeof mark[i]);

    queue <pii> qu;

    qu.push (fin);
    mark[fin.first][fin.second]= true;

    while (!qu.empty() && !mark[beg.first][beg.second]){

        pii top= qu.front(); qu.pop();

        for (int i=0;i<4;i++){

            int x= top.first  + move[i][0];
            int y= top.second + move[i][1];

            if (valid(x,y) && (mat[x][y]=='S') || (!mark[x][y] && dis[x][y]==dis[top.first][top.second]-1)){
                mark [x][y]= true;
                qu.push (pii(x,y));
            }
        }
    }

    string ret= "";

    pii now= beg;

    while (now!=fin){

        if (now!=beg)
            ret+= mat[now.first][now.second];

        char mini= 'z'+1;
        pii next;

        for (int i=0;i<4;i++){

            int x= now.first  + move[i][0];
            int y= now.second + move[i][1];

            if (valid(x,y) && mark[x][y] && dis[x][y]==dis[now.first][now.second]+1 && mat[x][y]<mini){
                mini= mat[x][y];
                next= pii(x,y);
            }
        }

        now= next;
    }

    return ret;
}

inline void bfs (){

    for (int i=1;i<=n;i++){
        memset (mark[i], false, sizeof mark[i]);
        memset (dis [i], -1, sizeof dis [i]);
    }

    queue <pii> qu;

    qu.push (beg);
    mark[beg.first][beg.second]= true;

    dis[beg.first][beg.second]= 0;

    while (!qu.empty() && !mark[fin.first][fin.second]){

        pii top= qu.front(); qu.pop();

        for (int i=0;i<4;i++){

            int x= top.first  + move[i][0];
            int y= top.second + move[i][1];

            if (valid (x,y) && !mark[x][y] && (mat[x][y]=='T' || flag[mat[x][y]-'a'])){
                mark [x][y]= true;
                dis  [x][y]= dis[top.first][top.second] + 1;
                qu.push (pii(x,y));
            }
        }
    }

    if (mark[fin.first][fin.second] && dis[fin.first][fin.second] <= res){

        string tmp= setPath();

        if (((int)tmp.size()+1) < res){
            res= tmp.size() + 1;
            ans= tmp;
        }

        else if (tmp < ans){
            ans= tmp;
        }
    }
}

inline void check (int len){

    if (len==(int)Q.size()){

        memset (flag, false, sizeof flag);

        for (int i=0;i<(int)Q.size();i++)
            flag[Q[i]-'a']= true;

        bfs ();

        return;
    }

    for (char i= (Q.empty()) ? 'a' : Q.back()+1 ; i<='z' ; i++){
        Q.push_back (i);
        check (len);
        Q.pop_back();
    }
}

int main(){

    scanf ("%d%d%d", &n, &m, &k);

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            scanf (" %c", &mat[i][j]);

            if (mat[i][j]=='S')
                beg= pii(i,j);

            else if (mat[i][j]=='T')
                fin= pii(i,j);
        }

    for (int i=0;i<4;i++){

        int x= beg.first  + move[i][0];
        int y= beg.second + move[i][1];

        if (valid(x,y) && mat[x][y]=='T'){
            printf ("\n");
            return 0;
        }
    }

    check (k);

    if (res==INF){
        printf ("-1\n");
        return 0;
    }

    else
        cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

const int maxN= 50+5;
const int INF = 1000*1000*1000;

bool flag[30];
char mat [maxN][maxN];
int n,m,k,res=INF;
int dis[maxN][maxN];
int dp [maxN][maxN];
vector <char> Q;
pii beg, fin;
pii par[maxN][maxN];
string ans;

int move[4][2]= {{-1,0}, {1,0}, {0,-1}, {0,1}};

inline bool valid (int x, int y){
    return (x*y!=0) && (x<=n) && (y<=m);
}

inline bool cmp (const pii &a1, const pii &a2){
    return dp[a1.first][a1.second] < dp[a2.first][a2.second];
}
inline void setPath (){

    for (int i=1;i<=n;i++)
        memset (dis[i], -1, sizeof dis[i]);

    vector <pii> qu;

    qu.push_back (fin);

    dis[fin.first][fin.second]= 0;
    dp [fin.first][fin.second]= 0;

    for (int i=0; i<(int)qu.size();){

        int j=i;

        while (j<(int)qu.size()){
            if (dis[qu[j].first][qu[j].second]==dis[qu[i].first][qu[i].second])
                j++;
            else
                break;
        }

        sort (qu.begin()+i, qu.begin()+j, cmp);

        while (i<j){

            pii now= qu[i];

            for (int z=0;z<4;z++){

                int x= now.first  + move[z][0];
                int y= now.second + move[z][1];

                if (valid(x,y) && dis[x][y]==-1 && (mat[x][y]=='S' || flag[mat[x][y]-'a'])){
                    dis[x][y]= dis[now.first][now.second] + 1;
                    par[x][y]= now;
                    dp [x][y]= 2600*(mat[x][y]-'a') + i;
                    qu.push_back (pii(x,y));
                }
            }

            i++;
        }
    }

    if (dis[beg.first][beg.second]==-1 || (res<dis[beg.first][beg.second]))
        return;

    pii tmp= beg;
    string ret="";

    while (tmp!=fin){
        if (tmp!=beg)
            ret+= mat[tmp.first][tmp.second];
        tmp= par[tmp.first][tmp.second];
    }

    if ((int)ret.size()+1<res || ((int)ret.size()+1==res && ret<ans)){
        res= ret.size() + 1;
        ans= ret;
    }
}

inline void check (int len){

    if (len==(int)Q.size()){

        memset (flag, false, sizeof flag);

        for (int i=0;i<(int)Q.size();i++)
            flag[Q[i]-'a']= true;

        setPath();

        return;
    }

    for (char i= (Q.empty()) ? 'a' : Q.back()+1 ; i<='z' ; i++){
        Q.push_back (i);
        check (len);
        Q.pop_back();
    }
}

int main(){

    scanf ("%d%d%d", &n, &m, &k);

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            scanf (" %c", &mat[i][j]);

            if (mat[i][j]=='S')
                beg= pii(i,j);

            else if (mat[i][j]=='T')
                fin= pii(i,j);
        }

    for (int i=0;i<4;i++){

        int x= beg.first  + move[i][0];
        int y= beg.second + move[i][1];

        if (valid(x,y) && mat[x][y]=='T'){
            printf ("\n");
            return 0;
        }
    }

    check (k);

    if (res==INF){
        printf ("-1\n");
        return 0;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=-1;
   do{
      queue<PII> q;

      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (mi == -1){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else{
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == -1){
      cout << -1 << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }
      /*
      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }
      */
      if (kjg[ak.FI][ak.SE].size() > 0){
//         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   mi=2;
   jwb="asd";
   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

      cout << jwb << endl;

   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      cout << kjg[ak.FI][ak.SE] << endl;
      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         cout << kjg[ak.FI][ak.SE] << endl;
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      queue<PII> q;

      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

      cout << jwb << endl;

   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }

                  cout << kjg[ui][uj] + sc[ni][nj] << endl;
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      queue<PII> q;

      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            int ni=ui + ari[k];
            int nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1 << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj,ui,uj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

//         cout << ui << " " << uj << " = " << kjg[ui][uj] << endl;

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c) && (sc[ni][nj] != 'S')){
               if (sc[ni][nj] == 'T'){
						if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
					}else if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if ((int)kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if ((int)kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if ((int)kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }

   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

string s,jwb;
PII u,aw;
priority_queue<pair<PII,PII> > pq;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
int kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

void bektrek(int y, int x){
   if ((aw.FI==y) && (aw.SE == x)){
      return;
   }else{
      bektrek(y-ari[kjg[y][x]], x-arj[kjg[y][x]]);
      s+=sc[y][x];
   }
}

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb=-1;
   mi=2123123123;
   do{
      RESET(kjg,-1);
      while (!pq.empty()) pq.pop();

      pq.push(MP(MP(0,-1*(int)'S'),aw));
      kjg[aw.FI][aw.SE]=0;

      h=2123123125;
      while (!pq.empty()){
         u=pq.top().SE;
         a=pq.top().FI.FI;
         pq.pop();

         if (sc[u.FI][u.SE] == 'T'){
            h=-a;
            break;
         }

         REP(k,4){
            ni=u.FI + ari[k];
            nj=u.SE + arj[k];

            if (!((0<=ni) && (ni<r) && (0<=nj) && (nj<c))) continue;
            if (sc[ni][nj] == 'T'){
               kjg[ni][nj]=k;
               pq.push(MP(MP(a-1,-1*(int)sc[ni][nj]),MP(ni,nj)));
               continue;
            }
            if (boleh[sc[ni][nj]-'a'] == 1) continue;
            if (kjg[ni][nj] == -1){
               kjg[ni][nj]=k;
               pq.push(MP(MP(a-1,-1*(int)sc[ni][nj]),MP(ni,nj)));
            }
         }
      }

      if (h <= mi){
         s="";
         bektrek(u.FI-ari[kjg[u.FI][u.SE]], u.SE-arj[kjg[u.FI][u.SE]]);

         if (mi > h){
            mi=h;
            jwb=s;
         }else if (h==mi){
            jwb=min(jwb, s);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == 2123123123){
      cout << -1 << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj,ui,uj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         cout << ui << " " << uj << " = " << kjg[ui][uj] << endl;

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if ((int)kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if ((int)kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if ((int)kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }

   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj,ui,uj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }

   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define HIUG 2123123123
#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

queue<PII> q;
string s,jwb;
PII u,aw,ak;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
string kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
         if (sc[i][j] == 'T'){
            ak=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=HIUG;
   do{
      REP(i,r){
         REP(j,c){
            kjg[i][j]="";
         }
      }

      q.push(aw);
      while (!q.empty()){
         int ui,uj;
         ui=q.front().FI;
         uj=q.front().SE;
         q.pop();

         REP(k,4){
            ni=ui + ari[k];
            nj=uj + arj[k];

            if ((0<=ni) && (ni<r) && (0<=nj) && (nj<c)){
               if (boleh[sc[ni][nj]-'a'] == 0){
                  if (kjg[ni][nj].size() == 0){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                     q.push(MP(ni,nj));
                  }else if ((kjg[ni][nj].size() == kjg[ui][uj].size()+1) && (kjg[ni][nj] > kjg[ui][uj] + sc[ni][nj])){
                     kjg[ni][nj]=kjg[ui][uj] + sc[ni][nj];
                  }
               }
            }
         }

         cout << kjg[ak.FI][ak.SE] << endl;
      }

      if (kjg[ak.FI][ak.SE].size() > 0){
         kjg[ak.FI][ak.SE].erase(kjg[ak.FI][ak.SE].size()-1,1);
         if (kjg[ak.FI][ak.SE].size() < mi){
            mi=kjg[ak.FI][ak.SE].size();
            jwb=kjg[ak.FI][ak.SE];
         }else if (kjg[ak.FI][ak.SE].size() == mi){
            jwb=min(jwb, kjg[ak.FI][ak.SE]);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == HIUG){
      cout << -1  << endl;
   }else{
      cout << jwb << endl;
   }

   system("pause");
   return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <set>
#include <stack>
#include <queue>

#define REP(a,b) for (int a=0; a<b; a++)
#define FORU(a,b,c) for (int a=b; a<=c; a++)
#define FORD(a,b,c) for (int a=b; a>=c; a--)
#define RESET(a,b) memset(a,b, sizeof a)

#define LOLO long long
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second

using namespace std;

string s,jwb;
PII u,aw;
priority_queue<pair<PII,PII> > pq;
int r,c,bts,a,h,mi,ni,nj;
char sc[55][55];
int boleh[27];
int kjg[55][55];
int ari[4]={-1,0,1,0};
int arj[4]={0,1,0,-1};

void bektrek(int y, int x){
   if ((aw.FI==y) && (aw.SE == x)){
      return;
   }else{
      bektrek(y-ari[kjg[y][x]], x-arj[kjg[y][x]]);
      s+=sc[y][x];
   }
}

int main(){
//   freopen("in.txt", "r", stdin);
//   freopen("ot.txt", "w", stdout);

   scanf("%d%d%d", &r,&c,&bts);
   REP(i,r){
      scanf("%s", sc[i]);

      REP(j,c){
         if (sc[i][j] == 'S'){
            aw=MP(i,j);
         }
      }
   }

   REP(i,26){
      boleh[i]=1;
   }
   REP(i,bts){
      boleh[i]=0;
   }

   jwb="";
   mi=2123123123;
   do{
      RESET(kjg,-1);
      while (!pq.empty()) pq.pop();

      pq.push(MP(MP(0,-1*(int)'S'),aw));
      kjg[aw.FI][aw.SE]=0;

      h=2123123125;
      while (!pq.empty()){
         u=pq.top().SE;
         a=pq.top().FI.FI;
         pq.pop();

         if (sc[u.FI][u.SE] == 'T'){
            h=-a;
            break;
         }

         REP(k,4){
            ni=u.FI + ari[k];
            nj=u.SE + arj[k];

            if (!((0<=ni) && (ni<r) && (0<=nj) && (nj<c))) continue;
            if (sc[ni][nj] == 'T'){
               kjg[ni][nj]=k;
               pq.push(MP(MP(a-1,-1*(int)sc[ni][nj]),MP(ni,nj)));
               continue;
            }
            if (boleh[sc[ni][nj]-'a'] == 1) continue;
            if (kjg[ni][nj] == -1){
               kjg[ni][nj]=k;
               pq.push(MP(MP(a-1,-1*(int)sc[ni][nj]),MP(ni,nj)));
            }
         }
      }

      if (h <= mi){
         s="";
         bektrek(u.FI-ari[kjg[u.FI][u.SE]], u.SE-arj[kjg[u.FI][u.SE]]);

         if (mi > h){
            mi=h;
            jwb=s;
         }else if (h==mi){
            jwb=min(jwb, s);
         }
      }
   }while (next_permutation(boleh, boleh+26));

   if (mi == 2123123123){
      cout << -1 << endl;
   }else{
      cout << jwb << endl;
   }
   return 0;
}


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 50 + 13;
const int M = N * N;

int n, m, k;
char f[N][N];
int stx, sty, finx, finy;

char c[4];
bool used[300];

pt q[N * N];
int tail, head;
int d[2][N][N];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int ansVal = INF;
string ans;
string best;

inline bool cmp (const pair <char, pt>& a, const pair <char, pt>& b)
{
    if (a.ft != b.ft)
    {
        if (a.ft == 'T')
            return true;

        if (b.ft == 'T')
            return false;

        return a.ft < b.ft;
    }

    return a.sc < b.sc;
}

void restore (int stx, int sty)
{
    vector <pt> cur;
    cur.pb(mp(stx, sty));

    while (true)
    {
        vector <pair <char, pt> > neibs;

        forn(i, sz(cur))
        {
            int x = cur[i].ft, y = cur[i].sc;

            forn(j, 4)
            {
                int tx = x + dx[j], ty = y + dy[j];

                if (!correct(tx, ty, n, m) || d[0][x][y] + 1 != d[0][tx][ty])
                    continue;

                neibs.pb(mp(f[tx][ty], mp(tx, ty)));
            }
        }

        sort(all(neibs), cmp);
        neibs.erase(unique(all(neibs)), neibs.end());

        cur.clear();
        //assert(!neibs.empty());

        if (neibs.empty())
        {
            cout << 100500 << endl;
            exit(0);
        }

        if (neibs[0].ft == 'T')
            return;

        ans.pb(neibs[0].ft);

        forn(i, sz(neibs))
            if (neibs[i].ft == neibs[0].ft)
                cur.pb(neibs[i].sc);
            else
                break;
    }
}

/*
bool dfs (int x, int y)
{
    if (x == finx && y == finy)
        return true;

    vector <pair <char, pt> > neib;

    forn(i, 4)
    {
        int tx = x + dx[i], ty = y + dy[i];

        if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
            continue;

        if (d[0][x][y] + 1 + d[1][tx][ty] != d[0][finx][finy])
            continue;

        neib.pb(mp(f[tx][ty], mp(tx, ty)));
    }

    sort(all(neib), cmp);

    forn(i, sz(neib))
        if (dfs(neib[i].sc.ft, neib[i].sc.sc))
        {
            if (x != stx || y != sty)
                ans.pb(f[x][y]);

            return true;
        }

    return false;
}
*/

void bfs (int idx, int stx, int sty, int finx, int finy)
{
    memset(d[idx], 63, sizeof(d[idx]));
    d[idx][stx][sty] = 0;

    tail = head = 0;
    q[tail++] = mp(stx, sty);

    while (head != tail)
    {
        int x = q[head].ft, y = q[head].sc;
        head++;
        if (head == M)
            head = 0;

        forn(i, 4)
        {
            int tx = x + dx[i], ty = y + dy[i];

            if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
                continue;

            if (d[idx][x][y] + 1 < d[idx][tx][ty])
            {
                d[idx][tx][ty] = d[idx][x][y] + 1;
                q[tail++] = mp(tx, ty);
                if (tail == M)
                    tail = 0;
            }
        }
    }
}

void go (int pos)
{
    if (pos == k)
    {
        bfs(0, stx, sty, finx, finy);

        if (d[0][finx][finy] > ansVal)
            return;

        ansVal = d[0][finx][finy];

        //bfs(1, finx, finy, stx, sty);

        restore(stx, sty);

        if (sz(ans) < sz(best) || (sz(ans) == sz(best) && ans < best))
            best = ans;

        ans = "";

        return;
    }
    else
    {
        char stc = 'a';
        if (pos != 0)
            stc = c[pos - 1] + 1;

        for (char curc = stc; curc <= 'z'; curc++)
        {
            c[pos] = curc;
            used[curc] = true;
            go(pos + 1);
            used[curc] = false;
        }
    }
}

int main()
{

    cin >> n >> m >> k;

    gets(f[0]);
    forn(i, n)
        gets(f[i]);

    forn(i, n)
        forn(j, m)
        {
            if (f[i][j] == 'S')
                stx = i, sty = j;

            if (f[i][j] == 'T')
                finx = i, finy = j;
        }

    used['S'] = used['T'] = true;
    best = string(n * m, 'z');

    go(0);

    if (ansVal == INF)
    {
        puts("-1");
        return 0;
    }

    puts(best.c_str());

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 50 + 13;

int n, m, k;
char f[N][N];
int neibx[4][N][N];
int neiby[4][N][N];
int szneib[N][N];
vector <pair <char, pt> > neib[N][N];
int stx, sty, finx, finy;

int stackx[N * N], stacky[N * N];
int szst = 0;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int used[300];
int curk = 0;

int ansx[N * N], ansy[N * N];
int szans = INF;

inline bool cmp (const pair <char, pt>& a, const pair <char, pt>& b)
{
    if (a.ft != b.ft)
    {
        if (a.ft == 'T')
            return true;

        if (b.ft == 'T')
            return false;

        return a.ft < b.ft;
    }

    return a.sc < b.sc;
}

int usedd[N][N];

void dfs (int x, int y)
{
    stackx[szst] = x;
    stacky[szst++] = y;
    usedd[x][y] = true;

    if (x == finx && y == finy)
    {
        if (szst < szans)
        {
            szans = szst;
            memcpy(ansx, stackx, szst * sizeof(int));
            memcpy(ansy, stacky, szst * sizeof(int));
        }

        usedd[x][y] = false;
        szst--;

        return;
    }

    if (curk > k)
    {
        szst--;
        usedd[x][y] = false;
        return;
    }

    forn(i, szneib[x][y])
    {
        int tx = neibx[i][x][y], ty = neiby[i][x][y];

        if (usedd[tx][ty])
            continue;

        int dd = abs(tx - finx) + abs(ty - finy);

        if (szst + dd > szans)
            continue;

        if (used[f[tx][ty]] == 0)
            curk++;

        used[f[tx][ty]]++;

        dfs(tx, ty);

        used[f[tx][ty]]--;

        if (used[f[tx][ty]] == 0)
            curk--;
    }

    usedd[x][y] = false;

    szst--;
}

int dist (int x, int y, int tx, int ty)
{
    return abs(x - tx) + abs(y - ty);
}

int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> n >> m >> k;

    gets(f[0]);
    forn(i, n)
        gets(f[i]);

    forn(i, n)
        forn(j, m)
        {
            if (f[i][j] == 'S')
                stx = i, sty = j;

            if (f[i][j] == 'T')
                finx = i, finy = j;
        }

    if (abs(stx - finx) + abs(sty - finy) == 1)
    {
        puts("");
        return 0;
    }

    forn(i, n)
        forn(j, m)
        {
            forn(t, 4)
            {
                int tx = i + dx[t], ty = j + dy[t];

                if (!correct(tx, ty, n, m))
                    continue;

                neib[i][j].pb(mp(f[tx][ty], mp(tx, ty)));
            }

            sort(all(neib[i][j]), cmp);
            szneib[i][j] = sz(neib[i][j]);

            forn(k, szneib[i][j])
                neibx[k][i][j] = neib[i][j][k].sc.ft, neiby[k][i][j] = neib[i][j][k].sc.sc;
        }

    dfs(stx, sty);

    if (szans != INF)
    {
        for1(i, szans - 2)
            putchar(f[ansx[i]][ansy[i]]);

        puts("");

        return 0;
    }

    puts("-1");

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 50 + 13;
const int M = N * N;

int n, m, k;
char f[N][N];
int stx, sty, finx, finy;

char c[4];
bool used[300];

pt q[N * N];
int tail, head;
int d[2][N][N];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int ansVal = INF;
string ans;
string best;

inline bool cmp (const pair <char, pt>& a, const pair <char, pt>& b)
{
    if (a.ft != b.ft)
    {
        if (a.ft == 'T')
            return true;

        if (b.ft == 'T')
            return false;

        return a.ft < b.ft;
    }

    return a.sc < b.sc;
}

void restore (int stx, int sty)
{
    vector <pt> cur;
    cur.pb(mp(stx, sty));

    while (true)
    {
        vector <pair <char, pt> > neibs;

        forn(i, sz(cur))
        {
            int x = cur[i].ft, y = cur[i].sc;

            forn(j, 4)
            {
                int tx = x + dx[j], ty = y + dy[j];

                if (!correct(tx, ty, n, m) || d[0][x][y] + 1 + d[1][tx][ty] != d[0][finx][finy])
                    continue;

                neibs.pb(mp(f[tx][ty], mp(tx, ty)));
            }
        }

        sort(all(neibs), cmp);
        neibs.erase(unique(all(neibs)), neibs.end());

        cur.clear();
        assert(!neibs.empty());

        if (neibs[0].ft == 'T')
            return;

        ans.pb(neibs[0].ft);

        forn(i, sz(neibs))
            if (neibs[i].ft == neibs[0].ft)
                cur.pb(neibs[i].sc);
            else
                break;
    }
}

/*
bool dfs (int x, int y)
{
    if (x == finx && y == finy)
        return true;

    vector <pair <char, pt> > neib;

    forn(i, 4)
    {
        int tx = x + dx[i], ty = y + dy[i];

        if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
            continue;

        if (d[0][x][y] + 1 + d[1][tx][ty] != d[0][finx][finy])
            continue;

        neib.pb(mp(f[tx][ty], mp(tx, ty)));
    }

    sort(all(neib), cmp);

    forn(i, sz(neib))
        if (dfs(neib[i].sc.ft, neib[i].sc.sc))
        {
            if (x != stx || y != sty)
                ans.pb(f[x][y]);

            return true;
        }

    return false;
}
*/

void bfs (int idx, int stx, int sty, int finx, int finy)
{
    memset(d[idx], 63, sizeof(d[idx]));
    d[idx][stx][sty] = 0;

    tail = head = 0;
    q[tail++] = mp(stx, sty);

    while (head != tail)
    {
        int x = q[head].ft, y = q[head].sc;
        head++;
        if (head == M)
            head = 0;

        forn(i, 4)
        {
            int tx = x + dx[i], ty = y + dy[i];

            if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
                continue;

            if (d[idx][x][y] + 1 < d[idx][tx][ty])
            {
                d[idx][tx][ty] = d[idx][x][y] + 1;
                q[tail++] = mp(tx, ty);
                if (tail == M)
                    tail = 0;
            }
        }
    }
}

void go (int pos)
{
    if (pos == k)
    {
        bfs(0, stx, sty, finx, finy);

        if (d[0][finx][finy] > ansVal)
            return;

        ansVal = d[0][finx][finy];

        bfs(1, finx, finy, stx, sty);

        restore(stx, sty);

        if (sz(ans) < sz(best) || (sz(ans) == sz(best) && ans < best))
            best = ans;

        ans = "";

        return;
    }
    else
    {
        char stc = 'a';
        if (pos != 0)
            stc = c[pos - 1] + 1;

        for (char curc = stc; curc <= 'z'; curc++)
        {
            c[pos] = curc;
            used[curc] = true;
            go(pos + 1);
            used[curc] = false;
        }
    }
}

int main()
{

    cin >> n >> m >> k;

    gets(f[0]);
    forn(i, n)
        gets(f[i]);

    forn(i, n)
        forn(j, m)
        {
            if (f[i][j] == 'S')
                stx = i, sty = j;

            if (f[i][j] == 'T')
                finx = i, finy = j;
        }

    used['S'] = used['T'] = true;
    best = string(n * m, 'z');

    go(0);

    if (ansVal == INF)
    {
        puts("-1");
        return 0;
    }

    puts(best.c_str());

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 50 + 13;
const int M = N * N;

int n, m, k;
char f[N][N];
int stx, sty, finx, finy;

char c[4];
bool used[300];

pt q[N * N];
int tail, head;
int d[2][N][N];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int ansVal = INF;
string ans;
string best;

inline bool cmp (const pair <char, pt>& a, const pair <char, pt>& b)
{
    if (a.ft != b.ft)
    {
        if (a.ft == 'T' || b.ft == 'S')
            return true;

        if (a.ft == 'S' || b.ft == 'T')
            return false;

        return a.ft < b.ft;
    }

    return a.sc < b.sc;
}

void restore (int stx, int sty)
{
    vector <pt> cur;
    cur.pb(mp(stx, sty));

    while (true)
    {
        vector <pair <char, pt> > neibs;

        forn(i, sz(cur))
        {
            int x = cur[i].ft, y = cur[i].sc;

            forn(j, 4)
            {
                int tx = x + dx[j], ty = y + dy[j];

                if (!correct(tx, ty, n, m) || d[0][x][y] + 1 != d[0][tx][ty])
                    continue;

                neibs.pb(mp(f[tx][ty], mp(tx, ty)));
            }
        }

        sort(all(neibs), cmp);

        cur.clear();
        assert(!neibs.empty());

        if (neibs[0].ft == 'T')
            return;

        ans.pb(neibs[0].ft);

        forn(i, sz(neibs))
            if (neibs[i].ft == neibs[0].ft)
                cur.pb(neibs[i].sc);
            else
                break;
    }
}

/*
bool dfs (int x, int y)
{
    if (x == finx && y == finy)
        return true;

    vector <pair <char, pt> > neib;

    forn(i, 4)
    {
        int tx = x + dx[i], ty = y + dy[i];

        if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
            continue;

        if (d[0][x][y] + 1 + d[1][tx][ty] != d[0][finx][finy])
            continue;

        neib.pb(mp(f[tx][ty], mp(tx, ty)));
    }

    sort(all(neib), cmp);

    forn(i, sz(neib))
        if (dfs(neib[i].sc.ft, neib[i].sc.sc))
        {
            if (x != stx || y != sty)
                ans.pb(f[x][y]);

            return true;
        }

    return false;
}
*/

void bfs (int idx, int stx, int sty, int finx, int finy)
{
    memset(d[idx], 63, sizeof(d[idx]));
    d[idx][stx][sty] = 0;

    tail = head = 0;
    q[tail++] = mp(stx, sty);

    while (head != tail)
    {
        int x = q[head].ft, y = q[head].sc;
        head++;
        if (head == M)
            head = 0;

        forn(i, 4)
        {
            int tx = x + dx[i], ty = y + dy[i];

            if (!correct(tx, ty, n, m) || !used[f[tx][ty]])
                continue;

            if (d[idx][x][y] + 1 < d[idx][tx][ty])
            {
                d[idx][tx][ty] = d[idx][x][y] + 1;
                q[tail++] = mp(tx, ty);
                if (tail == M)
                    tail = 0;
            }
        }
    }
}

void go (int pos)
{
    if (pos == k)
    {
        bfs(0, stx, sty, finx, finy);

        if (d[0][finx][finy] > ansVal)
            return;

        ansVal = d[0][finx][finy];

        //bfs(1, finx, finy, stx, sty);

        restore(stx, sty);

        if (sz(ans) < sz(best) || (sz(ans) == sz(best) && ans < best))
            best = ans;

        ans = "";

        return;
    }
    else
    {
        char stc = 'a';
        if (pos != 0)
            stc = c[pos - 1] + 1;

        for (char curc = stc; curc <= 'z'; curc++)
        {
            c[pos] = curc;
            used[curc] = true;
            go(pos + 1);
            used[curc] = false;
        }
    }
}

int main()
{

    cin >> n >> m >> k;

    gets(f[0]);
    forn(i, n)
        gets(f[i]);

    forn(i, n)
        forn(j, m)
        {
            if (f[i][j] == 'S')
                stx = i, sty = j;

            if (f[i][j] == 'T')
                finx = i, finy = j;
        }

    used['S'] = used['T'] = true;
    best = string(n * m, 'z');

    go(0);

    if (ansVal == INF)
    {
        puts("-1");
        return 0;
    }

    puts(best.c_str());

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 50 + 13;

int n, m, k;
char f[N][N];
int neibx[4][N][N];
int neiby[4][N][N];
int szneib[N][N];
vector <pair <char, pt> > neib[N][N];
int stx, sty, finx, finy;

int stackx[N * N], stacky[N * N];
int szst = 0;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int used[300];
int curk = 0;

void dfs (int x, int y)
{
    stackx[szst] = x;
    stacky[szst++] = y;

    if (x == finx && y == finy)
    {
        for1(i, szst - 2)
        {
            int curx = stackx[i], cury = stacky[i];

            putchar(f[curx][cury]);
        }

        puts("");

        exit(0);
    }

    if (curk > k)
    {
        szst--;
        return;
    }

    forn(i, szneib[x][y])
    {
        int tx = neibx[i][x][y], ty = neiby[i][x][y];

        if (used[f[tx][ty]] == 0)
            curk++;

        used[f[tx][ty]]++;

        dfs(tx, ty);

        used[f[tx][ty]]--;

        if (used[f[tx][ty]] == 0)
            curk--;
    }

    szst--;
}

int dist (int x, int y, int tx, int ty)
{
    return abs(x - tx) + abs(y - ty);
}

int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> n >> m >> k;

    gets(f[0]);
    forn(i, n)
        gets(f[i]);

    forn(i, n)
        forn(j, m)
        {
            if (f[i][j] == 'S')
                stx = i, sty = j;

            if (f[i][j] == 'T')
                finx = i, finy = j;
        }

    if (abs(stx - finx) + abs(sty - finy) == 1)
    {
        puts("");
        return 0;
    }

    forn(i, n)
        forn(j, m)
        {
            forn(t, 4)
            {
                int tx = i + dx[t], ty = j + dy[t];

                if (!correct(tx, ty, n, m))
                    continue;

                if (dist(stx, sty, i, j) + 1 + dist(tx, ty, finx, finy) != dist(stx, sty, finx, finy))
                    continue;

                neib[i][j].pb(mp(f[tx][ty], mp(tx, ty)));
            }

            sort(all(neib[i][j]));
            szneib[i][j] = sz(neib[i][j]);

            forn(k, szneib[i][j])
                neibx[k][i][j] = neib[i][j][k].sc.ft, neiby[k][i][j] = neib[i][j][k].sc.sc;
        }

    dfs(stx, sty);

    puts("-1");

    return 0;
}