优先队列+BFS;
//http://acm.nyist.net/JudgeOnline/problem.php?pid=1100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int n,m,vis[102][102];
char map[102][102];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int mon[102];
struct node{
int x,y;
int money;
friend bool operator< (node n1, node n2){
return n1.money>n2.money;
}
};
int check(int x,int y){
if(x>=n||(y>=m)||(x<0)||(y<0))return 0;
if(vis[x][y]==1)return 0;
if(map[x][y]=='#')return 0;
return 1;
}
int bfs(int x1,int y1){
vis[x1][y1]=1;
priority_queue<node>q;
struct node p,t;
p.x=x1;
p.y=y1;
p.money=0;
q.push(p);
while(!q.empty()){
t=q.top();
q.pop();
int x=t.x,y=t.y;
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(check(nx,ny)){
vis[nx][ny]=1;
if(map[nx][ny]=='l'){
return t.money;
}
p.x=nx;p.y=ny;
p.money=t.money+map[nx][ny]-'A'+1;
q.push(p);
}
}
}
return -1;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
getchar();
int a,b;
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%c",&map[i][j]);
if(map[i][j]=='s'){
a=i;b=j;
}
}
getchar();
}
printf("%d\n",bfs(a,b));
}
return 0;
}