#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int64_t ll;
typedef pair<int,int> ii;
#define EL printf("\n")
#define pb push_back
#define mp make_pair
#define X first
#define Y second
struct ke {
int v, c;
ll w;
ke(int v, int c, ll w) {
this->v = v;
this->c = c;
this->w = w;
}
};
struct data {
int u, c;
ll d;
data(int u, int c, ll d) {
this->u = u;
this->c = c;
this->d = d;
}
bool operator < (const data &other) const {
return d > other.d;
}
};
const int N = 150000;
const ll oo = 1e16;
int n, m, C, q, s, t, u, v, c;
ll w, d[N];
vector<ke> a[N];
priority_queue<data> heap;
void dijkstra()
{
for (int i=1;i<=n;i++) d[i] = oo;
d[s] = 0ll;
heap.push(data(s,-1,d[s]));
while (!heap.empty()) {
data top = heap.top();
heap.pop();
u = top.u;
if (d[u] != top.d) continue;
for (int i=0;i<a[u].size();i++) {
v = a[u][i].v;
c = a[u][i].c;
w = a[u][i].w;
if (c != top.c and d[v] > d[u] + w) {
d[v] = d[u] + w;
heap.push(data(v,c,d[v]));
}
}
}
for (int i=1;i<=n;i++) if (d[i] == oo) d[i] = -1;
}
int main()
{
//freopen("INP.INP","r",stdin);
//freopen("OUT.OUT","w",stdout);
scanf("%d %d %d", &n, &m, &C);
while (m--) {
scanf("%d %d %I64d %d", &u, &v, &w, &c);
a[u].pb(ke(v,c,w));
}
scanf("%d %d", &s, &q);
dijkstra();
while (q--) {
scanf("%d", &t);
printf("%I64d\n", d[t]);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgaW50NjRfdCAgIGxsOwp0eXBlZGVmIHBhaXI8aW50LGludD4gaWk7CgojZGVmaW5lIEVMIHByaW50ZigiXG4iKQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIFggIGZpcnN0CiNkZWZpbmUgWSAgc2Vjb25kCgpzdHJ1Y3Qga2UgewogICAgaW50IHYsIGM7CiAgICBsbCAgdzsKICAgIGtlKGludCB2LCBpbnQgYywgbGwgdykgewogICAgICAgIHRoaXMtPnYgPSB2OwogICAgICAgIHRoaXMtPmMgPSBjOwogICAgICAgIHRoaXMtPncgPSB3OwogICAgfQp9OwoKc3RydWN0IGRhdGEgewogICAgaW50IHUsIGM7CiAgICBsbCAgZDsKICAgIGRhdGEoaW50IHUsIGludCBjLCBsbCBkKSB7CiAgICAgICAgdGhpcy0+dSA9IHU7CiAgICAgICAgdGhpcy0+YyA9IGM7CiAgICAgICAgdGhpcy0+ZCA9IGQ7CiAgICB9CiAgICBib29sIG9wZXJhdG9yIDwgKGNvbnN0IGRhdGEgJm90aGVyKSBjb25zdCB7CiAgICAgICAgcmV0dXJuIGQgPiBvdGhlci5kOwogICAgfQp9OwoKY29uc3QgaW50ICAgTiA9IDE1MDAwMDsKY29uc3QgbGwgICAgb28gPSAxZTE2OwppbnQgICAgICAgICBuLCBtLCBDLCBxLCBzLCB0LCB1LCB2LCBjOwpsbCAgICAgICAgICB3LCBkW05dOwp2ZWN0b3I8a2U+ICBhW05dOwpwcmlvcml0eV9xdWV1ZTxkYXRhPiBoZWFwOwoKdm9pZCBkaWprc3RyYSgpCnsKICAgIGZvciAoaW50IGk9MTtpPD1uO2krKykgZFtpXSA9IG9vOwogICAgZFtzXSA9IDBsbDsKICAgIGhlYXAucHVzaChkYXRhKHMsLTEsZFtzXSkpOwogICAgd2hpbGUgKCFoZWFwLmVtcHR5KCkpIHsKICAgICAgICBkYXRhIHRvcCA9IGhlYXAudG9wKCk7CiAgICAgICAgaGVhcC5wb3AoKTsKICAgICAgICB1ID0gdG9wLnU7CiAgICAgICAgaWYgKGRbdV0gIT0gdG9wLmQpIGNvbnRpbnVlOwogICAgICAgIGZvciAoaW50IGk9MDtpPGFbdV0uc2l6ZSgpO2krKykgewogICAgICAgICAgICB2ID0gYVt1XVtpXS52OwogICAgICAgICAgICBjID0gYVt1XVtpXS5jOwogICAgICAgICAgICB3ID0gYVt1XVtpXS53OwogICAgICAgICAgICBpZiAoYyAhPSB0b3AuYyBhbmQgZFt2XSA+IGRbdV0gKyB3KSB7CiAgICAgICAgICAgICAgICBkW3ZdID0gZFt1XSArIHc7CiAgICAgICAgICAgICAgICBoZWFwLnB1c2goZGF0YSh2LGMsZFt2XSkpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaT0xO2k8PW47aSsrKSBpZiAoZFtpXSA9PSBvbykgZFtpXSA9IC0xOwp9CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiSU5QLklOUCIsInIiLHN0ZGluKTsKICAgIC8vZnJlb3BlbigiT1VULk9VVCIsInciLHN0ZG91dCk7CgogICAgc2NhbmYoIiVkICVkICVkIiwgJm4sICZtLCAmQyk7CiAgICB3aGlsZSAobS0tKSB7CiAgICAgICAgc2NhbmYoIiVkICVkICVJNjRkICVkIiwgJnUsICZ2LCAmdywgJmMpOwogICAgICAgIGFbdV0ucGIoa2UodixjLHcpKTsKICAgIH0KCiAgICBzY2FuZigiJWQgJWQiLCAmcywgJnEpOwoKICAgIGRpamtzdHJhKCk7CgogICAgd2hpbGUgKHEtLSkgewogICAgICAgIHNjYW5mKCIlZCIsICZ0KTsKICAgICAgICBwcmludGYoIiVJNjRkXG4iLCBkW3RdKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=