//#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include using namespace std; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // namespace debug { template struct rge { c b, e; }; template rge range(c i, c j) { return rge{i, j}; } template char elo(...); template auto elo(c* a) -> decltype(cerr << *a, 0); struct stream { ~stream() { cerr << endl; } template typename enable_if (0) != 1, stream&>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template typename enable_if (0) == 1, stream&>::type operator<<(c i) { return *this << range(begin(i), end(i)); } template stream& operator<<(pair p) { return *this << "(" << p.first << ", " << p.second << ")"; } template stream& operator<<(rge d) { *this << "["; for (auto it=d.b; it!=d.e; it++) *this << ", " + 2 * (it == d.b) << *it; return *this << "]"; } stream& _dbg(const string& s, int i, int b) { return *this; } template stream& _dbg(const string& s, int i, int b, c arg, cs ... args) { if (i == s.size()) return (*this << ": " << arg << ""); b += (s[i] == '(') + (s[i] == '[') + (s[i] == '{'); b -= (s[i] == ')') + (s[i] == ']') + (s[i] == '}'); if (s[i] == ',' && b == 0) return (*this << ": " << arg << " ")._dbg(s, i+1, b, args...); return (s[i] == ' ' ? *this : *this << s[i])._dbg(s, i+1, b, arg, args...); } };} #define dout debug::stream() #define dbg(...) ((dout << ">> ")._dbg(#__VA_ARGS__, 0, 0, __VA_ARGS__)) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // #define f first #define s second #define sc scanf #define pr printf #define mp make_pair #define pb push_back #define all(x) x.begin(),x.end() #define ss(x) ((int)((x).size())) #define rep0(i, b) for(int (i)=(0);i<(b);(i)++) #define rep1(i, b) for(int (i)=(1);i<=(b);(i)++) #define rep(i, a, b) for(int (i)=(a);i<=(b);(i)++) #define per(i, a, b) for(int (i)=(b);i>=(a);(i)--) #define lowb(v, x) (lower_bound(all(v),(x))-(v).begin()) #define uppb(v, x) (upper_bound(all(v),(x))-(v).begin()) #define upgrade ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));} template pair operator-(pair a, pair b) { return mp(a.f-b.f, a.s-b.s); } template pair operator+(pair a, pair b) { return mp(a.f+b.f, a.s+b.s); } template void umin(p& a, const q& b) { if (a > b) a = b; } template void umax(p& a, const q& b) { if (a < b) a = b; } using lf=long double; using ll=long long; using cll=const ll; using cint=const int; using pll=pair; using pii=pair; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // const ll inf = 1000000000000000005; const int N = 100010; int n, m, q; ll dis [N]; ll wei [3]; ll out = 0; unordered_map e [N]; void relax(int u, ll d){ if (dis[u] <= d) return; if (dis[u] != inf) out -= dis[u]; dis[u] = d; out += dis[u]; for (pair p : e[u]){ int v = p.f; int w = p.s; relax(v, dis[u] + wei[w]); } } int main (){ scanf ("%d%d%d%lld%lld", &n, &m, &q, &wei[1], &wei[2]); while (m--){ int a, b, c; char type [5]; scanf ("%d%d%s", &a, &b, type); if (type[0] == 'O'){ c = 1; }else{ c = 2; } e[a][b] = c; e[b][a] = c; } rep(i, 0, N - 1){ dis[i] = inf; } relax(0, 0); int now = n; while (q--){ int a, b; scanf ("%d%d", &a, &b); for (pair p : e[a]){ int v = p.f; int w = p.s; if (e[b].find(v) != e[b].end()){ int val = (w - e[b][v] + 3) % 3; if (val != 0) e[now][v] = val; continue; } e[now][v] = w; } for (pair p : e[b]){ int v = p.f; int w = (3 - p.s) % 3; if (e[a].find(v) != e[a].end()){ continue; } e[now][v] = w; } ll m = inf; for (pair p : e[now]){ int v = p.f; int w = p.s; umin(m, dis[v] + wei[w]); } relax(now, m); for (pair p : e[now]){ int v = p.f; int w = p.s; relax(v, dis[now] + wei[w]); } printf ("%lld\n", out); now += 1; } return 0; }