Problem: There is an evil creature in a square on N-by-M grid (2 \leq N, M \leq 100), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use several mirrors to reflect laser beams. There are some obstacles on the grid and you have a limited number of mirrors. Please find out whether it is possible to kill the creature, and if possible, find the minimum number of mirrors.

There are two types of single-sided mirrors; type P mirrors can be placed at the angle of 45 or 225 degrees from east-west direction, and type Q mirrors can be placed with at the angle of 135 or 315 degrees. For example, four mirrors are located properly, laser go through like the following.

<image>

Note that mirrors are single-sided, and thus back side (the side with cross in the above picture) is not reflective. You have A type P mirrors, and also A type Q mirrors (0 \leq A \leq 10). Although you cannot put mirrors onto the squares with the creature or the laser generator, laser beam can pass through the square. Evil creature is killed if the laser reaches the square it is in.



Input

Each test case consists of several lines.

The first line contains three integers, N, M, and A. Each of the following N lines contains M characters, and represents the grid information. '#', '.', 'S', 'G' indicates obstacle, empty square, the location of the laser generator, and the location of the evil creature, respectively. The first line shows the information in northernmost squares and the last line shows the information in southernmost squares. You can assume that there is exactly one laser generator and exactly one creature, and the laser generator emits laser beam always toward the south.

Output

Output the minimum number of mirrors used if you can kill creature, or -1 otherwise.

Examples

Input

3 3 2
S#.
...
.#G


Output

2


Input

3 3 1
S#.
...
.#G


Output

-1


Input

3 3 1
S#G
...
.#.


Output

2


Input

4 3 2
S..
...
..#
.#G


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int H, W, A;
vector<string> s(H);
int sx, sy, gx, gy;
const int MAX_V = 4*11*11*100*100;
int d[MAX_V];

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

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

struct Node {
    int x, y, p, q, k, id;
    Node(){}
    Node(int _x, int _y, int _p, int _q, int _k) : x(_x), y(_y), p(_p), q(_q), k(_k), id(-1) {
        if (!inside(x, y)) return;
        if (p < 0 || q < 0) return;
        if (s[x][y] == '#') return;
        if (s[x][y] == 'S' && k == 2) return;
        id = 4*11*11*100*x + 4*11*11*y + 4*11*p + 4*q + k;
    }
    Node(int _id) : id(_id) {
        k = _id % 4; _id /= 4;
        q = _id % 11; _id /= 11;
        p = _id % 11; _id /= 11;
        y = _id % 100; _id /= 100;
        x = _id;
    }
    void print() {
        output(x, y, p, q, k, id);
    }
};

int dijkstra() {
    using State = pair<int, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    fill(d, d + MAX_V, inf);

    Node ns(sx, sy, A, A, 0);
    d[ns.id] = 0;
    pq.push(State(0, ns.id));

    while (!pq.empty()) {
        int cost, id;
        tie(cost, id) = pq.top(); pq.pop();
        if (d[id] < cost) continue;
        Node u(id);

        int x = u.x;
        int y = u.y;
        int p = u.p;
        int q = u.q;
        int k = u.k;

        if (x == gx && y == gy) {
            return cost;
        }

        vector<pair<Node, int>> cands; // v, cost(u->v)

        if (s[x][y] == 'S') {
            cands.emplace_back(Node(x + dx[k], y + dy[k], p, q, k), 0);
        }
        else if (k == 0) {
            cands.emplace_back(Node(x, y - 1, p, q - 1, 3), 1);
            cands.emplace_back(Node(x, y + 1, p - 1, q, 1), 1);
            cands.emplace_back(Node(x + 1, y, p, q, 0), 0);
        }
        else if (k == 1) {
            cands.emplace_back(Node(x - 1, y, p, q - 1, 2), 1);
            cands.emplace_back(Node(x + 1, y, p - 1, q, 0), 1);
            cands.emplace_back(Node(x, y + 1, p, q, 1), 0);
        }
        else if (k == 2) {
            cands.emplace_back(Node(x, y - 1, p - 1, q, 3), 1);
            cands.emplace_back(Node(x, y + 1, p, q - 1, 1), 1);
            cands.emplace_back(Node(x - 1, y, p, q, 2), 0);
        }
        else if (k == 3) {
            cands.emplace_back(Node(x - 1, y, p - 1, q, 2), 1);
            cands.emplace_back(Node(x + 1, y, p, q - 1, 0), 1);
            cands.emplace_back(Node(x, y - 1, p, q, 3), 0);
        }

        for (const auto& p : cands) {
            Node v;
            int c;
            tie(v, c) = p;
            if (v.id == -1) continue;
            if (d[v.id] > d[u.id] + c) {
                d[v.id] = d[u.id] + c;
                pq.push(State(d[v.id], v.id));
            }
        }
    }

    return -1;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> H >> W >> A;
    s.resize(H);
    rep(i, H) {
        cin >> s[i];
        rep(j, W) {
            if (s[i][j] == 'S') {
                sx = i; sy = j;
            }
            if (s[i][j] == 'G') {
                gx = i; gy = j;
            }
        }
    }

    cout << dijkstra() << endl;
}