Factorization

Time limit3sMemory limit512 MB

Summary
Given a prime p and residues a0, a1, find b0, b1 in [0, p-1] with b0*b1 = a0 and b0+b1 = a1 mod p, or report none.
Level

Medium6 of 10

Topics
Math, Number theory, Binary search, Implementation
Solved
No attempts yet

Problem

Integer factorization plays an important role in many cryptographic systems. It asks, for a given positive composite number nn, to find two positive integers pp and qq such that n=pqn = pq and 1<p≤q<n1 < p \le q < n. It is a well-known NP-intermediate candidate, though, and no algorithm solves it in polynomial time yet.

Taylor, a number theorist, made another factorization problem as follows.

Given a prime number pp and two integers a0,a1∈{0,1,…,p−1}a_0, a_1 \in \{0, 1, \ldots, p - 1\}, find two integers b0,b1∈{0,1,…,p−1}b_0, b_1 \in \{0, 1, \ldots, p - 1\} such that a0≡b0⋅b1(modp)a_0 \equiv b_0 \cdot b_1 \pmod{p} and a1≡b0+b1(modp)a_1 \equiv b_0 + b_1 \pmod{p}.

"This factoring is way cooler, in that it can be computed efficiently," Taylor said. Now he invites you to enjoy this new variant of factorization.

Input

The first line contains an integer 1≤T≤1001 \le T \le 100, the number of test cases. Each test case takes one line containing three non-negative integers p,a0,a1p, a_0, a_1 separated by a single space.

Output

For each test case, output one line containing b0b_0 and b1b_1 in ascending order separated by a single space if b0b_0 and b1b_1 satisfy the two equations. If there are multiple solutions, you may output any of them. If there is no solution, output −1-1.

Constraints

  • 1≤T≤1001 \le T \le 100
  • 1<p<2311 < p < 2^{31} and pp is prime.
  • a0,a1∈{0,1,…,p−1}a_0, a_1 \in \{0, 1, \ldots, p - 1\}.

Examples1

  1. Example 1

    Input
    2
    2 1 0
    2 1 1
    
    Expected output
    1 1
    -1