program pascal;
type matrice=array[0..151,0..3502] of longint;
graf=array[0..151,0..151] of longint;
var s,t:matrice; px,py:array[1..8000] of longint;
a,cost:graf; f,g:text;
n,m,k,p,maxt:longint;
procedure citire;
var i,x,y,c:longint;
begin
assign(f,'amenzi.in'); reset(f);
readln(f,n,m,k,p);
for i:=1 to m do
begin
readln(f,x,y,c);
inc(a[x,0]); a[x,a[x,0]]:=y; cost[x,y]:=c;
inc(a[y,0]); a[y,a[y,0]]:=x; cost[y,x]:=c;
end;
for i:=1 to k do
begin
readln(f,x,y,c);
inc(s[x,y],c);
end;
maxt:=0;
for i:=1 to p do
begin
readln(f,px[i],py[i]);
if py[i]>maxt then maxt:=py[i];
end;
end;
function max(a,b:longint):longint;
begin
if a>b then max:=a
else max:=b;
end;
procedure dinamica;
var i,j,k,nod:longint;
begin
for i:=1 to n do t[i,0]:=-1;
t[1,0]:=s[1,0];
for i:=1 to maxt do
for j:=1 to n do
begin
t[j,i]:=-1;
if t[j,i-1]<>-1 then t[j,i]:=t[j,i-1]+s[j,i];
for k:=1 to a[j][0] do
begin
nod:=a[j][k];
if (i-cost[j,nod]>-1) then
if (cost[j,nod]>0) and (t[nod,i-cost[j,nod]]<>-1) then
t[j,i]:=max(t[j,i],t[nod,i-cost[j,nod]]+s[j,i]);
end;
end;
end;
procedure afisare;
var i,y,x:longint;
begin
assign(g,'amenzi.out'); rewrite(g);
for i:=1 to p do writeln(g,t[px[i],py[i]]);
close(f); close(g);
end;
begin
citire;
dinamica;
afisare;
end.