Input The first line of input consists of an integers T where 1≤T≤1000, the number of test cases. Then follow T lines, each containing four integers a, n, b, m satisfying 1≤n,m≤10e9, 0≤a<n, 0≤b<m. Also, you may assume gcd(n,m)=1.Output For each test…