#include<stdio.h>
#define mt 3500
#define INF -42000000
typedef struct nod {int x,c; nod *d; } nod;
typedef struct amenda { int x,c; amenda *d; } amenda;
nod *v[160];
amenda *a[3600];
int n,m,k,p;
long s[3600][160];
void addn(int x,int y,int c)
{
nod *p=new nod;
p->x=x;
p->c=c;
p->d=v[y];
v[y]=p;
}
void adda(int x,int y,int c)
{
amenda *p=new amenda;
p->x=x;
p->c=c;
p->d=a[y];
a[y]=p;
}
void SOLVE();
void READ()
{ int i,x,y,c;
FILE *f,*g;
f=fopen("amenzi.in","r");
g=fopen("amenzi.out","w");
fscanf(f,"%d %d %d %d",&n,&m,&k,&p);
for(i=1;i<=m;i++)
{ fscanf(f,"%d %d %d",&x,&y,&c);
addn(x,y,c);
addn(y,x,c); }
for(i=1;i<=k;i++)
{ fscanf(f,"%d %d %d",&x,&y,&c);
adda(x,y,c);
}
SOLVE();
for(i=1;i<=p;i++)
{ fscanf(f,"%d %d",&x,&y);
if(s[y][x]!=INF) fprintf(g,"%ld\n",s[y][x]);
else fprintf(g,"-1\n");
}
fclose(f);
fclose(g);
}
void SOLVE()
{ int i,j,x,t,c;
nod *q;
amenda *p;
for(i=0;i<=mt;i++)
for(j=1;j<=n;j++)
s[i][j]=INF;
s[0][1]=0;
p=a[0];
while(p)
{if(p->x==1) s[0][1]+=p->c; p=p->d; }
for(i=1;i<=mt;i++)
{
for(j=1;j<=n;j++)
{ q=v[j];
s[i][j]=s[i-1][j];
while(q)
{
x=q->x;
t=q->c;
if(i-t>=0 && s[i][j]<s[i-t][x]) s[i][j]=s[i-t][x];
q=q->d;
}
}
p=a[i];
while(p)
{
j=p->x;
c=p->c;
if(s[i][j]!=INF) s[i][j]+=c;
p=p->d;
}
}
}
int main()
{
READ();
return 0;
}