5403: Defend Ponyville

内存限制:128 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

Changelings are going to attack Ponyville again! Their goal is to absorb the love inside all the ponies as their food! Unluckily, the defense of Ponyville is now too fragile to fight against them. Twilight Sparkle must reinforce the defense magic cast around Ponyville before Changelings' final attack.

 

There are nnn magic sources in Ponyville, together with m undirected connections. Each connection connects exactly 2 different magic sources, and there is at most 1 connection between 2 magic sources. The defense power is initially 0 . At any time, Twilight Sparkle can cast a spell to a set of n-1 connections ( the set cannot be empty ) that connects all the n sources (any source can reach other sources through these n-1 connections), and the defense power will increase by 1 . However, the same set of connections can be used only once every day to increase the defense power. The two sets are the same if and only if they have precisely the same connections. Twilight Sparkle only has t days to prepare before Changelings pour in, so every day she will gain as much defense power as possible.

 

But due to the unstable magic field, some connections may disappear in some days. Luckily, thanks to Twilight's research, we know that the probability for the j-th connection to exist on the i-th day (i=1,2,…,t)is qj+(pj−qj)a−(i−1) (0≤pj,qj≤1,pj≠qj), where a is a given constant. Twilight Sparkle wants to know the expectation of total defense power she can gain in ttt days. Can you help her and protect Ponyville?

 

输入

The first line contains 4 integers n,m,t,a (1≤n≤300,0≤m≤n(n−1)/2,1≤t≤108,1≤a≤109).

The following m lines are the m connections. The i-th line contains 6 integers ui,vi,a1i,b1i,a2i,b2i (1≤ui,vi≤n,ui≠vi,0≤a1i,a2i≤109,1≤b1i,b2i≤109), indicating that the i-th connection is between ui and vi , pi=a1i/b1i,qi=a2i/b2i (0≤pj,qj≤1,pj≠qj).

输出

One integer indicating the expectation of the total defense power Twilight Sparkle can get. You should output the answer modulo 998244353. Formally, let M=998244353. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and q  0 mod  M.Output the integer equal to p × q−1 mod M. In other words, output such an integer x that 0≤ x < M and xq ≡ p mod  M.

样例输入 复制

3 3 2 2
1 2 1 1 0 1
2 3 1 1 0 1
1 3 1 1 0 1

样例输出 复制

249561092