#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e5 + 5;
int in_type[nax];
vector<vi> queries[nax];
int g[nax];
vi odw[nax];
set<int> types[nax];
int ans[nax];
set<pair<int,int>> ready[nax];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
RI(i, q) ans[i] = -1;
RI(i, n) scanf("%d", &in_type[i]);
vector<vi> roads;
REP(_, m) {
int a, b, cost;
scanf("%d%d%d", &a, &b, &cost);
roads.pb(vi{cost,a,b});
}
RI(i, q) {
int a, b, cost;
scanf("%d%d%d", &a, &b, &cost);
queries[a].pb(vi{b,cost,i});
queries[b].pb(vi{a,cost,i});
}
sort(roads.begin(), roads.end());
RI(i, n) {
odw[i].pb(i);
g[i] = i;
types[i].insert(in_type[i]);
}
for(vi & road : roads) {
int a = g[road[1]];
int b = g[road[2]];
int cost = road[0];
if(a == b) continue;
if(sz(odw[a]) > sz(odw[b])) swap(a,b);
// a mniejsze
for(pii p : ready[a])
ready[b].insert(p);
ready[a].clear();
for(int x : odw[a]) {
g[x] = b;
odw[b].pb(x);
}
for(int x : types[a])
types[b].insert(x);
types[a].clear();
for(int x : odw[a])
for(vi & query : queries[x]) {
int y = query[0];
int least = query[1];
int q_id = query[2];
if(g[x] == g[y] && ans[q_id] == -1) {
if(sz(types[b])>=least)
ans[q_id] = cost;
else ready[b].insert(mp(least, q_id));
}
}
odw[a].clear();
while(!ready[b].empty()) {
auto it = ready[b].begin();
pii p = *it;
if(p.first > sz(types[b])) break;
ready[b].erase(it);
if(ans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