#Lutece0525. 猴子选大王

猴子选大王

Migrated from Lutece 525 猴子选大王

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

mm个猴子围成一圈,按顺时针编号,分别为11mm。现打算从中选出一个大王。经过协商,决定选大王的规则如下:从第一个开始顺时针报数,报到nn的猴子出圈,紧接着从下一个又从11顺时针循环报数,...,如此下去,最后剩下来的就是大王。

Input

第一行是一个正整数TT表示测试数据的组数。下面共有TT行,每行两个整数mmnn,用一个空格隔开,分别表示猴子的个数和报数nn1m1001\le m\le 1001n2001\le n\le 200

Output

每组数据对应有一个输出,表示大王的编号。

Samples

1
3 2
3

Resources

wxiaoping 2009年C语言第六次上机