#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int mod(const string &num, int a){
ll ret=0;
for(int i=0;i<(int)num.length();i++)
ret=(ret*10+(int)(num[i]-'0'))%a;
return ret;
}
string addBigNumbers(string number1, string number2) {
if (number1.length() > number2.length())
swap(number1, number2);
string sum = "";
int len1 = number1.length();
int len2 = number2.length();
int digitDiff = len2 - len1;
int carry = 0;
int intSum;
for (int i=len1-1; i>=0; i--) {
intSum = ((number1[i]-'0') + (number2[i+digitDiff]- '0') + carry);
sum.push_back(intSum%10 + '0');
carry = intSum/10;
}
for (int i=digitDiff-1; i>=0; i--) {
intSum = ((number2[i]-'0')+carry);
sum.push_back(intSum%10 + '0');
carry = intSum/10;
}
if (carry)
sum.push_back(carry+'0');
reverse(sum.begin(), sum.end());
return sum;
}
void solve(){
string a;
int b;
cin>>a>>b;
int m=mod(a,b);
if(m) m=b-m;
cout<<addBigNumbers(a,to_string(m));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
solve();
cout<<'\n';
}
}
Copy