Spaceship

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Bessie the cow has been abducted by aliens and is now trapped inside an alien spaceship! The spaceship has NN (1N60)(1\le N\le 60) rooms labeled 1N1\ldots N, with one-way doors connecting between some pairs of rooms (due to the strange alien technology at play, it is even possible for a door to lead from a room back to itself!). However, no two doors share the same starting and end room. Additionally, Bessie has a remote with buttons numbered 1K1\ldots K (1K60)(1 \le K \le 60).

The aliens will release Bessie if she can complete a strange task. First, they will choose two rooms, ss and tt (1s,tN)(1 \le s, t \le N), and two numbers, b_sb\_s and b_tb\_t (1b_s,b_tK)(1 \le b\_s, b\_t \le K). They will start Bessie in room ss and immediately have her press button b_sb\_s. Bessie will then proceed to navigate the ship while pressing buttons. There are a few rules for what Bessie can do:

  • In each room, after pressing exactly one button, she must choose to either exit through a door to another (possibly the same) room or stop.
  • Once Bessie presses a button, it is invalid for her to press the same button again unless, in the time between uses, she has pressed a button with a higher number. In other words, pressing button number xx will make it unavailable for use, while all buttons with numbers \<x\<x will be reset and again available for use.
  • If Bessie presses an invalid button, she automatically fails and the aliens will keep her.

Bessie is released only if she stops in room tt, the last button she pressed was b_tb\_t, and no invalid buttons were ever pressed.

Bessie is worried that she may not be able to complete the task. For QQ (1Q60)(1\le Q\le 60) queries, each consisting of what Bessie considers a likely choice of s,t,b_ss, t, b\_s, and b_tb\_t, Bessie wants to know the number of sequences of rooms and button presses that would lead to her release. Report your answers modulo 109+710^9 + 7 as they may be very large.

입력

The first line contains N,K,QN,K,Q.

The next NN lines each contain NN bits (each 0 or 1). The jj-th entry of the ii-th line is 1 if there exists a door from room ii to room jj, and 0 if no such door exists.

This is followed by QQ lines, each containing four integers b_sb\_s, ss, b_tb\_t, tt, denoting the starting button, starting room, final button, and final room respectively.

출력

The number of sequences for each of the QQ queries modulo 109+710^9+7 on separate lines.