Teleportation

Count length-L button sequences that move from ship S to ship T, where each ship has four outgoing transitions, modulo 10^4.

Medium6MatrixDynamic programmingGraphNo attempts yetTime limit2sMemory limit512 MB

Problem

The Galactic Confederation installed a new teleport system on its spaceships. Every ship has one teleport booth, and inside the booth there is a panel with four buttons. Each button carries a different letter, A, B, C or D, together with the number of the destination ship the user is transported to, instantly, when that button is pressed. Confederation ships are identified by the integers 1 to NN.

To use the system the user buys a ticket for each trip, and one trip is one button press. The panel has few buttons compared with the number of ships in the Confederation, so travelling from a ship SS to another ship TT may require a ticket for LL trips.

Look at the ships in the figure below. In the teleport booth of ship 3, pressing button B transports the user to ship 2. With trips left on the ticket, pressing button B again transports the user to ship 1.

Given the departure ship SS, the arrival ship TT and the number of trips LL written on the ticket, count the distinct button sequences that take the user from ship SS to ship TT. A sequence has exactly LL presses. For the ships in the figure, four distinct sequences with L=2L = 2 take a user from ship S=3S = 3 to ship T=1T = 1: CD, DA, AB and BB.

Input

The first line contains two integers NN and LL, the number of ships and the number of trips on the ticket. (1N1001 \le N \le 100, 0L<2300 \le L < 2^{30})

The second line contains two integers SS and TT, the departure ship and the arrival ship. (1S,TN1 \le S, T \le N)

Each of the next NN lines describes the panel of one teleport booth. The ii-th of those lines contains four integers AA, BB, CC and DD, the numbers written on the four buttons of ship ii. (1A,B,C,DN1 \le A, B, C, D \le N)

Output

Print one line with a single integer. Let rr be the number of distinct button sequences of length LL that take the user from ship SS to ship TT. Print rr modulo 10410^4.