#P7830. Divisibility

Divisibility

Divisibility

Problem Description

You are given two 1010-based integers bb and xx, and you are required to determine the following proposition is true or false: For arbitrary bb-based positive integer y=c1c2cny = \overline{c_1 c_2 \cdots c_n} (cic_i is the ii-th dight from left of yy), define f(y)=i=1nci\displaystyle f(y) = \sum_{i=1}^n c_i, if f(f(f(y)))\underbrace{f( f( \cdots f(y) \cdots ))}_{\infty} can be divided by xx, then yy can be divided by xx, otherwise yy can't be divided by xx.

Input

The first line contains a 1010-based integer t (1t105)t\ (1 \leq t \leq 10^5) — the number of test cases. For each test case, there is a single line containing two 1010-based integers bb and x (2b,x1018)x \ (2 \leq b,x \leq 10^{18}).

Output

For each test case, if the proposition is true, print "T", otherwise print "F" (without quotes).

Sample Input

1
10 3

Sample Output

T

Source

2020 Multi-University Training Contest 6