#nt302. 中国剩余定理2

中国剩余定理2

Chinese Remainder Theorem 2

Problem Description

There are TT test cases. Each case gives nn equations of the form x≡ai(modmi)x \equiv a_i \pmod{m_i}. Determine whether the system of equations has a solution.

Input Format

The first line contains one integer TT.

For each test case, the first line contains one integer nn, and the next nn lines each contain two integers ai,mia_i, m_i.

Output Format

For each test case, output one string Yes or No indicating whether a solution exists.

Sample Input

2
3
1 10
2 11
3 12
3
2 10
2 11
3 12

Sample Output

Yes
No

Constraints

It is guaranteed that T≤1000T \le 1000, 1≤n≤501 \le n \le 50, and 0≤ai<mi≤1050 \le a_i < m_i \le 10^5.