SP14761 ALMISPY - Almost-isosceles Pythagorean triple (easy)

Description

**(3, 4, 5)** is the smallest almost-isosceles Pythagorean triple, as **4 - 3 = 1**. Let **S = { (_a_, _a_+1, _c_) | _a_ $ ^{2} $ + (_a_+1) $ ^{2} $ = _c_ $ ^{2} $ with _a_ and _c_ positive integers}**. One can prove that the set **S** of almost-isosceles Pythagorean triples is infinite. There is an obvious total order on this set.

Input Format

The first line of input contains an integer **_T_**, the number of test cases. On each of the next **_T_** lines, your are given two integers **_n_** and **_m_**.

Output Format

For each test case, you have to find the **_n_**th triple **(_a_, _a_+1, _c_)** in the ordered set **S**, and print **_a_** and **_c_**. As the answer could not fit in a 64-bit container, simply output your answer modulo **_m_**.