#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int d[N][N];
int main()
{
    for (int t = 1, c, s, q; scanf("%d%d%d", &c, &s, &q), c | s | q; t++)
    {
        if (t > 1) putchar('\n');
        memset(d, 0x3f, sizeof(d));
        for (int i = 0, c1, c2, x; i < s; i++)
            scanf("%d%d%d", &c1, &c2, &x), d[c1][c2] = d[c2][c1] = x;
        for (int k = 1; k <= c; k++)
            for (int i = 1; i <= c; i++)
                for (int j = 1; j <= c; j++)
                    d[i][j] = min(d[i][j], max(d[i][k], d[k][j]));
        printf("Case #%d\n", t);
        for (int i = 0, c1, c2; i < q; i++)
        {
            scanf("%d%d", &c1, &c2);
            if (d[c1][c2] == 0x3f3f3f3f)
                puts("no path");
            else
                printf("%d\n", d[c1][c2]);
        }
    }
    return 0;
}