#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
while(*++ptr < ‘0‘ || *ptr > ‘9‘);
while(*ptr <= ‘9‘ && *ptr >= ‘0‘) n = (n << 1) + (n << 3) + (*ptr++ & 15);
return n;
}
const int maxn = 20000 + 10, maxm = 200000 + 10, maxk = 20 + 5, INF = 1 << 30;
struct Edge{
int to, val, next;
Edge(){}
Edge(int _t, int _v, int _n): to(_t), val(_v), next(_n){}
}e[maxm * 2];
int fir[maxn] = {0}, cnt = 0;
inline void ins(int u, int v, int w){
e[++cnt] = Edge(v, w, fir[u]); fir[u] = cnt;
e[++cnt] = Edge(u, w, fir[v]); fir[v] = cnt;
}
int n, m, k;
int pre[maxk] = {0}, p[maxk][maxk];
int dis[maxn];
bool inq[maxn];
int q[maxn], h, t;
void spfa(int S){
for(int i = 1; i <= n; i++){
dis[i] = INF;
inq[i] = false;
}
dis[S] = 0;
inq[S] = true;
h = t = 0;
q[t++] = S;
int u, v;
while(h != t){
u = q[h++]; if(h == maxn) h = 0;
inq[u] = false;
for(int i = fir[u]; i; i = e[i].next){
v = e[i].to;
if(dis[v] > dis[u] + e[i].val){
dis[v] = dis[u] + e[i].val;
if(!inq[v]){
inq[v] = true;
q[t++] = v; if(t == maxn) t = 0;
}
}
}
}
for(int i = 1; i <= k + 1; i++) p[S][i] = dis[i];
p[S][0] = dis[n];
}
int f[1048576][maxk];
void dp(){
int Max = (1 << k) - 1;
for(int st = 0; st <= Max; st++)
for(int i = 1; i <= k + 1; i++)
f[st][i] = -1;
f[0][1] = 0;
for(int st = 0; st <= Max; st++)
for(int i = 1; i <= k + 1; i++)
if(f[st][i] != -1)
for(int j = 2; j <= k + 1; j++)
if((st & pre[j]) == pre[j])
if(f[st | (1 << j - 2)][j] == -1 || f[st | (1 << j - 2)][j] > f[st][i] + p[i][j])
f[st | (1 << j - 2)][j] = f[st][i] + p[i][j];
int ans = INF;
for(int i = 1; i <= k + 1; i++)
if(f[Max][i] != -1) ans = min(ans, f[Max][i] + p[i][0]);
printf("%d\n", ans);
}
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
n = readint();
m = readint();
k = readint();
for(int u, v, w, i = 1; i <= m; i++){
u = readint();
v = readint();
w = readint();
ins(u, v, w);
}
int q = readint();
for(int a, b, i = 1; i <= q; i++){
a = readint();
b = readint();
pre[b] |= 1 << a - 2;
}
for(int i = 1; i <= k + 1; i++) spfa(i);
dp();
return 0;
}