#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in ("radiatie.in");
ofstream out ("radiatie.out");
const int MAXN = 15010 * 2;
int N, M, K;
vector < pair <int, int> > Graf[MAXN];
int H[MAXN * 2], First[MAXN * 2], Lvl[MAXN * 2];
int D[17][MAXN], Smen[17][MAXN];
int Log[MAXN], RMQ[17][MAXN];
int T[MAXN];
bool Viz[MAXN];
int now;
struct muchie
{
int a, b, c;
} X[MAXN];
struct comp
{
inline bool operator () (const muchie &A, const muchie &B) const
{
return A.c < B.c;
}
};
int find (int nod)
{
if (nod == T[nod])
return nod;
return (T[nod] = find (T[nod]));
}
void APM ()
{
int i, x, y, c, Tx, Ty;
for (i = 1; i <= N; i ++)
T[i] = i;
sort (X + 1, X + M + 1, comp ());
for (i = 1; i <= M; i ++){
x = X[i].a;
y = X[i].b;
c = X[i].c;
Tx = find (x);
Ty = find (y);
if (Tx != Ty){
T[Tx] = Ty;
Graf[x].push_back (make_pair (y, c));
Graf[y].push_back (make_pair (x, c));
}
}
}
void DFS (pair <int, int> nod, int father, int lev)
{
++ now;
H[now] = nod.first;
Lvl[now] = lev;
First[nod.first] = now;
D[0][nod.first] = father;
Smen[0][nod.first] = nod.second;
for (auto it = Graf[nod.first].begin (); it != Graf[nod.first].end (); ++ it){
if (Viz[it -> first])
continue;
Viz[it -> first] = 1;
DFS (*it, nod.first, lev + 1);
++ now;
H[now] = nod.first;
Lvl[now] = lev;
}
}
void Build_Log ()
{
int i;
for (i = 2; i < MAXN; i ++)
Log[i] = Log[i / 2] + 1;
}
void Build_RMQ ()
{
int i, j, a, b;
for (i = 1; i <= now; i ++)
RMQ[0][i] = i;
for (j = 1; (1 << j) <= now; j ++)
for (i = 1; i + (1 << j) <= now; i ++){
a = RMQ[j - 1][i];
b = RMQ[j - 1][i + (1 << (j - 1))];
if (Lvl[a] <= Lvl[b])
RMQ[j][i] = a;
else
RMQ[j][i] = b;
}
}
int LCA (int nod1, int nod2)
{
nod1 = First[nod1];
nod2 = First[nod2];
if (nod2 < nod1)
swap (nod1, nod2);
int dif = nod2 - nod1 + 1;
int log = Log[dif];
int a, b;
a = RMQ[log][nod1];
b = RMQ[log][nod2 - (1 << log) + 1];
if (Lvl[a] <= Lvl[b])
return a;
else
return b;
}
void Build_Smen ()
{
int i, j;
for (i = 1; (1 << i) <= N; i ++)
for (j = 1; j <= N; j ++){
D[i][j] = D[i - 1][D[i - 1][j]];
Smen[i][j] = max (Smen[i - 1][j], Smen[i - 1][D[i - 1][j]]);
}
}
int Query (int x, int y)
{
int i, dif = Lvl[First[x]] - Lvl[First[y]], Ans = -1;
for (i = 0; (1 << i) <= dif; i ++)
if (dif & (1 << i)){
Ans = max (Ans, Smen[i][x]);
x = D[i][x];
}
return Ans;
}
int Solve (int x, int y)
{
int lca, a, b;
lca = H[LCA (x, y)];
a = Query (x, lca);
b = Query (y, lca);
return max (a, b);
}
int main()
{
int i, a, b, c;
in >> N >> M >> K;
for (i = 1; i <= M; i ++)
in >> X[i].a >> X[i].b >> X[i].c;
APM ();
Viz[1] = 1;
DFS (make_pair (1, 0), 0, 1);
Build_Log ();
Build_RMQ ();
Build_Smen ();
while (K --){
in >> a >> b;
out << Solve (a, b) << "\n";
}
return 0;
}