#P2552. [AHOI2001] 团体操队形
[AHOI2001] 团体操队形
Description
There are group gymnastics members labeled . Their formation (either continuous formation or "Meihuazhuang" formation) can be arranged by rows or by columns. When arranged by rows (or columns), each row (or column) has positions.
Example 1: , , continuous formation arranged by rows. |1|2|3|4|5|6| |:-:|:-:|:-:|-|-|-| |7|8|9|10|11|12| |13|14|15|16|
Example 2: , , continuous formation arranged by columns. | 1 | 4 | 7 | 10 | 13 |16| | :-: | :-: | :-: | :-: | :-: |- | |2|5|8|11|14| |3|6|9|12|15|
Example 3: , , "Meihuazhuang" formation arranged by rows. | 1 | | 2 | | 3 | | 4 | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | | |5 | |6 | |7 | | |8 | | 9| |10| |11| | |12| |13| |14| | |15| |16| | | | |
Example 4: , , "Meihuazhuang" formation arranged by columns. | 1 | | 6 | | 11 | |16 | | :-: | :-: | :-: | :-: | :-: | :-: |:-:| | |4| |9 | |14| | |2| |7| |12| | | | |5| |10| |15| | |3| |8| |13| | |
Please write a program to output the row index and column index of the gymnast labeled .
Input Format
This problem contains multiple testcases. The first line has a single natural number , indicating that the following lines each describe one testcase. Each of the next lines contains five integers, denoting respectively: the number of people in the team, the formation code ( means continuous formation, and means "Meihuazhuang" formation), the arrangement method ( means arranged by rows, and means arranged by columns), the number of positions per row (or column), and the label of the gymnast being queried.
Output Format
Output integers. The -th pair of integers denotes the row index and column index for the -th query (no newline).
2
16 1 1 6 11
16 2 2 5 11
2 5 1 5
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号