#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;
}
