#include <iostream>
#include <algorithm>
using namespace std;
string add(string a, int b) {
int i = 0;
reverse(a.begin(), a.end());
while (b || i < a.size()) {
if (i >= a.size()) {
a.push_back('0');
}
int d = a[i] - '0';
int sum = d + (b % 10);
b += ((sum / 10) * 10);
b /= 10;
a[i] = '0' + (sum % 10);
i++;
}
reverse(a.begin(), a.end());
return a;
}
int mod(string a, int b) {
int i = 0;
int sum = 0;
while (i < a.size()) {
int d = a[i] - '0';
sum *= 10;
sum += d;
sum %= b;
i++;
}
return sum;
}
int main() {
int t;
cin >> t;
string x;
int y;
while (t--) {
cin >> x >> y;
int m = mod(x, y);
if (m % y == 0) {
cout << x << endl;
}
else {
m = (y - (m % y));
x = add(x, m);
cout << x << endl;
}
}
}
Copy