{"task": {"agent_timeout": 600, "task": "1069", "verifier_timeout": 7200, "instruction": "Please implement a Python 3 solution to the below problem.\nReason through the problem and:\n1. Restate the problem in plain English\n2. Conceptualize a solution first in plain English\n3. Write a pseudocode solution\n4. Save your solution as solution.py\nNo outside libraries are allowed.\n\n[BEGIN PROBLEM]\nBessie the cow has been abducted by aliens and is now trapped inside an alien\nspaceship! The spaceship has $N$ $(1\\le N\\le 60)$ rooms labeled $1\\ldots N$, with\none-way doors connecting between some pairs of rooms (due to the strange alien\ntechnology at play, it is even possible for a door to lead from a room back to\nitself!). However, no two doors share the same starting and end room.\nAdditionally, Bessie has a remote with buttons numbered $1\\ldots K$\n$(1 \\le K \\le 60)$.\n\nThe aliens will release Bessie if she can complete a strange task. First, they\nwill choose two rooms, $s$ and $t$ $(1 \\le s, t \\le N)$, and two numbers, $b_s$\nand $b_t$ $(1 \\le b_s, b_t \\le K)$. They will start Bessie in room $s$ and\nimmediately have her press button $b_s$. Bessie will then proceed to navigate\nthe ship while pressing buttons. There are a few rules for what Bessie can do:\n\nIn each room, after pressing exactly one button, she must choose to either\nexit through a door to another (possibly the same) room or stop.Once\nBessie presses a button, it is invalid for her to press the same button again\nunless, in the time between uses, she has pressed a button with a higher number.\nIn other words, pressing button number $x$ will make it unavailable for use, \nwhile all buttons with numbers $<x$ will be reset and again available for\nuse.If Bessie presses an invalid button, she automatically fails and the aliens\nwill keep her.\n\nBessie is released only if she stops in room $t$, the last button she pressed\nwas $b_t$, and no invalid buttons were ever pressed.\n\nBessie is worried that she may not be able to complete the task. For $Q$\n$(1\\le Q\\le 60)$ queries, each consisting of what Bessie considers a likely\nchoice of $s, t, b_s$, and $b_t$, Bessie wants to know the number of sequences\nof rooms and button presses that would lead to her release. Report your answers\nmodulo $10^9 + 7$ as they may be very large.\n\nINPUT FORMAT (input arrives from the terminal / stdin):\nThe first line contains $N,K,Q$.\n\nThe next $N$ lines each contain $N$ bits (each 0 or 1). The $j$-th entry of the\n$i$-th line is 1 if there exists a door from room $i$ to room $j$, and 0 if no\nsuch door exists.\n\nThis is followed by $Q$ lines, each containing four integers $b_s$, $s$, $b_t$,\n$t$, denoting the starting button, starting room, final button, and final room\nrespectively.\n\nOUTPUT FORMAT (print output to the terminal / stdout):\nThe number of sequences for each of the $Q$ queries modulo $10^9+7$ on separate\nlines.\n\nSAMPLE INPUT:\n6 3 8\n010000\n001000\n000100\n000010\n000000\n000001\n1 1 1 1\n3 3 1 1\n1 1 3 3\n1 1 1 5\n2 1 1 5\n1 1 2 5\n3 1 3 5\n2 6 2 6\nSAMPLE OUTPUT: \n1\n0\n1\n3\n2\n2\n0\n5\n\nThe doors connect rooms $1\\to 2$, $2 \\to 3$, $3\\to 4$, $4\\to 5$, and $6\\to 6$.\n\nFor the first query, Bessie must stop immediately after pressing the first\nbutton.\n\nFor the second query, the answer is clearly zero because there is no way to get\nto room 1 from room 3.\n\nFor the third query, Bessie's only option is to move from room 1 to room 2 to\nroom 3 while pressing buttons 1, 2, and 3.\n\nFor the fourth query, Bessie's pattern of movement is fixed, and she has three\npossible sequences of button presses:\n\n$(1,2,3,2,1)$$(1,2,1,3,1)$$(1,3,1,2,1)$\nFor the last query, Bessie has five possible sequences of button presses:\n\n$(2)$$(2,3,2)$$(2,3,1,2)$$(2,1,3,2)$$(2,1,3,1,2)$\nSAMPLE INPUT:\n6 4 6\n001100\n001110\n101101\n010111\n110111\n000111\n3 2 4 3\n3 1 4 4\n3 4 4 1\n3 3 4 3\n3 6 4 3\n3 1 4 2\nSAMPLE OUTPUT: \n26\n49\n29\n27\n18\n22\n\nThis test case satisfies the constraints for all subtasks aside from the first.\n\nSAMPLE INPUT:\n6 10 5\n110101\n011001\n001111\n101111\n111010\n000001\n2 5 2 5\n6 1 5 2\n3 4 8 3\n9 3 3 5\n5 1 3 4\nSAMPLE OUTPUT: \n713313311\n716721076\n782223918\n335511486\n539247783\n\nMake sure to output the answers modulo $10^9+7$.\n\nSCORING:\nIn test cases 4-7, $K\\le 5$ and $(b_s,s)$ is the same for all queries.In test cases 8-11, $b_s=K-1$ and $b_t=K$ for each query.In test cases 12-15, $N,K,Q\\le 20$.In test cases 16-23, there are no additional constraints.\n\n\nProblem credits: Benjamin Qi\n\n[END PROBLEM]\n", "memory": "2048m", "runnable": false, "difficulty": "medium", "language": "", "cpus": 1, "instruction_truncated": false, "category": "python_programming", "compose": false, "has_solution": true, "oracle": null, "docker_image": "", "taskset": "usaco", "tags": ["python", "programming", "usaco"]}, "runs": []}