#include <iostream>
using namespace std;
int a[100000] = { 0 };
int main()
{
int t;
int idx = 0;
cin >> t;
for (int i = 0;i < t;i++) {
int x, y;
cin >> x >> y;
int k = x;
for (int i = 0;i < 1e9;i++) {
if (k % y == 0) {
a[idx] = k;
idx++;
break;
}
k++;
}
}
for (int i = 0;i < idx;i++) {
cout << a[i] << endl;
}
}