#include <cstdio>
#include <cstring>
#include <algorithm>
using
namespace
std;
const
int
maxn = 100 + 10;
const
int
maxm = 1000 + 10;
const
long
long
IINF = 0xc0c0c0c0c0c0c0c0LL;
int
N, M, K;
char
C[maxn][maxm];
int
G[maxn][maxm];
long
long
d[maxm];
void
dfs(
int
from,
int
cur_r,
int
cur_c,
int
v,
long
long
sum) {
if
(cur_r < 1) cur_r = 1;
if
(cur_r > N) cur_r = N;
if
(cur_r == 1 && cur_c != from) {
d[cur_c] = max(d[cur_c], sum);
return
;
}
if
(cur_c - from == K || cur_c == M)
return
;
if
(C[cur_r][cur_c] ==
'$'
) sum += G[cur_r][cur_c];
else
if
(cur_r != 1) v += G[cur_r][cur_c];
dfs(from, cur_r+v, cur_c+1, v, sum);
dfs(from, cur_r+v-1, cur_c+1, v-1, sum);
dfs(from, cur_r+v+1, cur_c+1, v+1, sum);
}
void
read() {
for
(
int
i = 1; i <= N; i++)
for
(
int
j = 1; j <= M; j++)
scanf
(
" %c%d"
, &C[i][j], &G[i][j]);
}
void
solve() {
memset
(d, 0xc0,
sizeof
(d));
d[1] = 0;
for
(
int
i = 1; i <= M; i++) dfs(i, 1, i, 0, d[i]);
if
(C[1][M] ==
'$'
) d[M] += G[1][M];
printf
(
"%I64d\n"
, d[M]);
}
int
main()
{
while
(
scanf
(
"%d%d%d"
, &N, &M, &K) == 3) {
if
(!N && !M && !K)
return
0;
read();