408180: GYM103048 A Abstract Algebra

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Abstract Algebratime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

Cuber QQ has an Abstract algebra course this semester, and he has a problem in the latest problemset that he desperately needs your help.

Given $$$M=\{\begin{bmatrix} a & b\\ c & d \end{bmatrix}|a,b,c,d\in \mathbb{Z},ad-bc=1\}$$$ which is a multiplicative group. There is a nice property of this multiplicative group, that is, there are two generators $$$A=\begin{bmatrix} 1 & 1\\ 0 & 1 \end{bmatrix}$$$ and $$$B=\begin{bmatrix} 0 & 1\\ -1 & 0 \end{bmatrix}$$$, such that, $$$x\in M$$$ iff. $$$x=\prod _{i} x_i $$$ where $$$x_i\in \{A,B,A^{-1},B^{-1}\}$$$.

Now you are given an element $$$x\in M$$$, you need to find a sequence of $$$\{x_i\}$$$ such that $$$x=\prod _{i} x_i $$$ where $$$x_i\in \{A,B,A^{-1},B^{-1}\}$$$. To make your already-miserable life easier, it is guaranteed that there is at least one of $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ that equals to zero, i.e., $$$abcd=0$$$ for $$$x=\begin{bmatrix} a & b\\ c & d \end{bmatrix}$$$.

Input

The first line contains a single integer $$$T$$$ ($$$1\le T\le 10$$$) — the number of test cases.

Each of the next $$$T$$$ lines contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$-10^5\le a,b,c,d\le 10^5$$$, $$$ad-bc=1$$$, $$$abcd=0$$$), denoting $$$x=\begin{bmatrix} a & b\\ c & d \end{bmatrix}$$$.

Output

For each test case, in the first line, please output one integer $$$m$$$ ($$$1 \le m \le 4$$$). In the following $$$m$$$ lines, each line contains one character $$$c_i$$$ and one integer $$$a_i$$$ ($$$c_i\in \{\text{'A'},\text{'B'}\},-10^5\le a_i\le 10^5$$$), such that $$$x=c_1^{a_1}c_2^{a_2}\cdots c_m^{a_m} = \prod _{i} c_i^{a_i}$$$.

In case of multiple solutions, please output any one.

We guarantee that there is always at least one solution.

ExampleInput
3
1 1 0 1
-1 1 -1 0
-1 -1 0 -1
Output
1
A 1
2
A 1
B 1
2
A 1
B 2

加入题单

上一题 下一题 算法标签: