#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define cin(a,n) forn(i,n) cin >> a[i]
#define cout(a,n) forn(i,n) cout << a[i] << ' '
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(), a.end()
#define alln(a, n) a, a + n
#define rall(a) a.rbegin(), a.rend()
#define ralln(a) a,a+n, greater<int>()
#define yes "YES"
#define no "NO"
#define yn(b) cout<<(b?yes:no)<<'\n'
#define pb push_back
ll remainder(string,ll);
string ll_to_string(ll);
string adder(string, string);
void solve() {
string s,t,ans; int n;
cin >> s >> n;
ll r = remainder(s,n);
t = ll_to_string(n-r);
ans = adder(s, t);
cout << ans << '\n';
}
int main(void) {
FastIO;
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
ll remainder(string s, ll n) {
ll r = 0;
reverse(all(s));
while (!s.empty()) {
r = ((ll)r * 10 + s.back() - '0') % n;
s.pop_back();
}
return r;
}
string ll_to_string(ll n) {
string ans = "";
while (n) {
ans.push_back(n % 10 + '0');
n /= 10;
}
reverse(all(ans));
return ans;
}
string adder(string s, string t) {
if (s.length() > t.length()) swap(s, t);
reverse(all(s));
reverse(all(t));
string ans = "";
int CAR = 0;
forn(i, s.length()) {
int add = (s[i] - '0') + (t[i] - '0') + CAR;
ans.push_back(add % 10 + '0');
CAR = add / 10;
}
for (int i = s.length(); i < t.length(); i++) {
int add = t[i] - '0' + CAR;
ans.push_back(add % 10 + '0');
CAR = add / 10;
}
if (CAR) {
ans.push_back(CAR + '0');
}
reverse(all(ans));
return ans;
}
Copy