#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include "testlib.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)
using namespace std;
using namespace __gnu_pbds;
mt19937_64 gen(time(0));
int func(int x)
{
return gen() % x;
}
typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//const int mod = 1e9 + 7;
ld score(ll a, ll b)
{
if (a == b)
{
return 10.;
}
return ceil(((ld)a * a) / ((ld)b * b) * 10. * 100) / 100;
}
const int maxn = 1e6 + 66;
const int maxk = 1e6 + 66;
const int maxq = 3e7;
map <int, int> g[maxn];
bool used[maxk];
bool cas[maxk];
int a[maxn], b[maxn], c[maxn];
int castles[maxk];
int n, m, k, t, A, s;
int main(int argc, char * argv[])
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
setName("scored checker");
registerTestlibCmd(argc, argv);
int test_id = inf.readInt();inf.skipBlanks();
n = inf.readInt(1, maxn);inf.skipBlanks();
m = inf.readInt(n-1, 100000000);inf.skipBlanks();
k = inf.readInt(1, n);inf.skipBlanks();
t = inf.readInt();inf.skipBlanks();
A = inf.readInt();inf.skipBlanks();
s = inf.readInt(1, n);inf.skipBlanks();
--s;
for(int i = 0; i < m; ++i)
{
int x, y, w;
x = inf.readInt(1, n);inf.skipBlanks();
y = inf.readInt(1, n);inf.skipBlanks();
w = inf.readInt(0, 1000000000);inf.skipBlanks();
--x;
--y;
g[x][y] = w;
g[y][x] = w;
}
{
//
int uk = 0;
for(int i = 0; i < k; ++i)
{
castles[uk] = inf.readInt();inf.skipBlanks();
a[uk] = inf.readInt();inf.skipBlanks();
b[uk] = inf.readInt();inf.skipBlanks();
c[uk] = inf.readInt();inf.skipBlanks();
--castles[uk];
cas[castles[uk]] = 1;
if (!(a[uk] <= 0 && b[uk] <= 0)) ++uk;
}
k = uk;
}
inf.skipBlanks();
inf.readEof();
int coinsa = ans.readInt();ans.skipBlanks();
ans.readEof();
int coinsp = 0;
int cA = A, ct = t, v = s;
int q = ouf.readInt(0, maxq);
ouf.skipBlanks();
for(int i = 0; i < q; ++i)
{
int type = ouf.readInt(1, 2);
ouf.skipBlanks();
if (type == 2)
{
if (!cas[v])
quitf(_wa, "Try to capture the '%d'-th field", v + 1); else
if (used[v])
quitf(_wa, "Two or more times a '%d' castle is captured", v + 1);
else
{
if (cA < c[v])
quitf(_wa, "Haven't '%d' warriors for capture castle '%d'", c[v] - cA, v + 1);
cA += a[v];
coinsp += b[v];
}
used[v] = 1;
}
else
{
int to = ouf.readInt(1, n);
--to;
if (g[v].count(to) == 0) quitf(_wa, "Haven't an edge from '%d' to '%d'", v + 1, to + 1);
if (ct + g[v][to] > t) quitf(_wa, "Time is out on the action'%d'", i + 1);
ct += g[v][to];
v = to;
}
ouf.skipBlanks();
}
ouf.readEof();
if (coinsa < coinsp)
quitf(_fail, "Bad author sultion");
quitp(score(coinsp, coinsa), "jr='%d' ur='%d'", coinsa, coinsp);
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKLy8jcHJhZ21hIEdDQyB0YXJnZXQoInNzZSxzc2UyLHNzZTMsc3NzZTMsc3NlNCxwb3BjbnQsYWJtLG1teCIpCgojaW5jbHVkZSAidGVzdGxpYi5oIgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KCgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCiNkZWZpbmUgcGIgcHVzaF9iY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gPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICBuID0gaW5mLnJlYWRJbnQoMSwgbWF4bik7aW5mLnNraXBCbGFua3MoKTsKICAgIG0gPSBpbmYucmVhZEludChuLTEsIDEwMDAwMDAwMCk7aW5mLnNraXBCbGFua3MoKTsKICAgIGsgPSBpbmYucmVhZEludCgxLCBuKTtpbmYuc2tpcEJsYW5rcygpOwogICAgdCA9IGluZi5yZWFkSW50KCk7aW5mLnNraXBCbGFua3MoKTsKICAgIEEgPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICBzID0gaW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgIC0tczsKICAgIAogICAgZm9yKGludCBpID0gMDsgaSA8IG07ICsraSkKICAgIHsKICAgICAgICBpbnQgeCwgeSwgdzsKICAgICAgICB4ID0gaW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICB5ID0gaW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICB3ID0gaW5mLnJlYWRJbnQoMCwgMTAwMDAwMDAwMCk7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICAtLXg7CiAgICAgICAgLS15OwogICAgICAgIGdbeF1beV0gPSB3OwogICAgICAgIGdbeV1beF0gPSB3OwogICAgfQogICAgewogICAgICAgIC8vCiAgICAgICAgaW50IHVrID0gMDsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgazsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgY2FzdGxlc1t1a10gPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICAgICAgICAgIGFbdWtdID0gaW5mLnJlYWRJbnQoKTtpbmYuc2tpcEJsYW5rcygpOwogICAgICAgICAgICBiW3VrXSA9IGluZi5yZWFkSW50KCk7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICAgICAgY1t1a10gPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICAgICAgICAgIC0tY2FzdGxlc1t1a107CiAgICAgICAgICAgIGNhc1tjYXN0bGVzW3VrXV0gPSAxOwogICAgICAgICAgICBpZiAoIShhW3VrXSA8PSAwICYmIGJbdWtdIDw9IDApKSArK3VrOwogICAgICAgIH0KICAgICAgICBrID0gdWs7CiAgICB9CiAgICBpbmYuc2tpcEJsYW5rcygpOwogICAgaW5mLnJlYWRFb2YoKTsKICAgIGludCBjb2luc2EgPSBhbnMucmVhZEludCgpO2Fucy5za2lwQmxhbmtzKCk7CiAgICBhbnMucmVhZEVvZigpOwogICAgaW50IGNvaW5zcCA9IDA7CiAgICBpbnQgY0EgPSBBLCBjdCA9IHQsIHYgPSBzOwogICAgaW50IHEgPSBvdWYucmVhZEludCgwLCBtYXhxKTsKICAgIG91Zi5za2lwQmxhbmtzKCk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgcTsgKytpKQogICAgewogICAgICAgIGludCB0eXBlID0gb3VmLnJlYWRJbnQoMSwgMik7CiAgICAgICAgb3VmLnNraXBCbGFua3MoKTsKICAgICAgICBpZiAodHlwZSA9PSAyKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKCFjYXNbdl0pCiAgICAgICAgICAgICAgICBxdWl0Zihfd2EsICJUcnkgdG8gY2FwdHVyZSB0aGUgJyVkJy10aCBmaWVsZCIsIHYgKyAxKTsgZWxzZSAKICAgICAgICAgICAgaWYgKHVzZWRbdl0pCiAgICAgICAgICAgICAgICBxdWl0Zihfd2EsICJUd28gb3IgbW9yZSB0aW1lcyBhICclZCcgY2FzdGxlIGlzIGNhcHR1cmVkIiwgdiArIDEpOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChjQSA8IGNbdl0pCiAgICAgICAgICAgICAgICAgICAgcXVpdGYoX3dhLCAiSGF2ZW4ndCAnJWQnIHdhcnJpb3JzIGZvciBjYXB0dXJlIGNhc3RsZSAnJWQnIiwgY1t2XSAtIGNBLCB2ICsgMSk7CiAgICAgICAgICAgICAgICBjQSArPSBhW3ZdOwogICAgICAgICAgICAgICAgY29pbnNwICs9IGJbdl07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZFt2XSA9IDE7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGludCB0byA9IG91Zi5yZWFkSW50KDEsIG4pOwogICAgICAgICAgICAtLXRvOwogICAgICAgICAgICBpZiAoZ1t2XS5jb3VudCh0bykgPT0gMCkgcXVpdGYoX3dhLCAiSGF2ZW4ndCBhbiBlZGdlIGZyb20gJyVkJyB0byAnJWQnIiwgdiArIDEsIHRvICsgMSk7CiAgICAgICAgICAgIGlmIChjdCArIGdbdl1bdG9dID4gdCkgICBxdWl0Zihfd2EsICJUaW1lIGlzIG91dCBvbiB0aGUgYWN0aW9uJyVkJyIsIGkgKyAxKTsKICAgICAgICAgICAgY3QgKz0gZ1t2XVt0b107CiAgICAgICAgICAgIHYgPSB0bzsKICAgICAgICB9CiAgICAgICAgb3VmLnNraXBCbGFua3MoKTsKICAgIH0KICAgIG91Zi5yZWFkRW9mKCk7CiAgICBpZiAoY29pbnNhIDwgY29pbnNwKQogICAgICAgIHF1aXRmKF9mYWlsLCAiQmFkIGF1dGhvciBzdWx0aW9uIik7CiAgICBxdWl0cChzY29yZShjb2luc3AsIGNvaW5zYSksICJqcj0nJWQnIHVyPSclZCciLCBjb2luc2EsIGNvaW5zcCk7CiAgICByZXR1cm4gMDsKfQo=