#include <iostream>
using namespace std;
const int N = 1e5 + 5;
int main() {
int T, x, y, z;
cin >> T;
while (T--) {
cin >> x >> y;
if (x <= y) {
cout << y << endl;
}
else {
int z = (x % y) + x + 1;
cout << z << endl;
}
}
return 0;
}