#P8956. 「CGOI-3」招魂术
「CGOI-3」招魂术
Background
A sea of skeletons in the Necropolis!
The anti-magic ball of the Stronghold!
The three back-row shooters of the Tower!
The armor-piercing Behemoth of the Fortress!
The full magic-resistance Black Dragon of the Dungeon!

Tower ↑
Team Shen is here to play Heroes of Might and Magic 3.
Problem Description
Necromancy is the core spell of the Necropolis faction.
A hero with Necromancy can gain a certain number of skeletons after each battle, based on the number of enemies killed. We use integers to describe Necromancy. Let denote the number of skeletons obtained by killing enemies. Then:
$$F_{A,B}(1)=A,F_{A,B}(2)=B,F_{A,B}(x)=\lfloor \sqrt{F_{A,B}(x-2)F_{A,B}(x-1)}\rfloor+1\;(x \ge 3)$$Now Team Shen wants to recruit a hero in the tavern. Hero 1 has Necromancy parameters , and Hero 2 has Necromancy parameters . To compare whose Necromancy is stronger, compute the value of the following expression:
Of course Team Shen knows how to do it, but he wants to test you.
Input Format
The first line contains an integer , the number of queries.
The next lines each contain five integers .
Output Format
Output lines. For each query, output the answer modulo .
It is recommended to use sqrtl and long double for square roots.
4
5 2 10 1 8
11 4 5 1 4
19 1 9 8 10
114 51 4 1919 810
998244317
998242817
939523984
604148977
Hint
Sample Explanation
In the sample explanation, let be , and be .
For the first query:
-
The first terms of are .
-
The first terms of are .
So the final answer is $(1-2)\times(8-10)\times(3-5)\times(5-8)\times(4-7)=-36$, and the result modulo is .
Constraints
For of the testdata, .
For another of the testdata, each query satisfies .
For another of the testdata, .
For of the testdata, and .
Translated by ChatGPT 5