#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> P) {
  out << '(' << P.first << ',' << P.second << ')';
  return out;
}
const ll INF64 = 8000000000000000000LL;
const ll INF = 0x3f3f3f3f;
const ll MOD = ll(1e9 + 7);
const ld PI = acos(-1);
const ld eps = 1e-9;
ll mypow(ll a, ll b) {
  ll res = 1LL;
  while (b) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
const ll maxn = 20;
ll arr[maxn];
ll dp[maxn];
void solve() {
  memset(arr, (0), sizeof(arr));
  memset(dp, (0), sizeof(dp));
  string str;
  ll a;
  cin >> str >> a;
  for (ll i = ((ll)str.size()); i < 20; i++) str = '0' + str;
  ll sum = 0;
  for (ll i = 0; i < (ll)20; i++) sum += (str[i] - '0');
  ll ans = 0;
  ll kk = 1;
  for (ll i = 19; i >= 0; i--, kk *= 10) {
    if (sum <= a) {
      cout << ans << '\n';
      return;
    }
    if (str[i] == '0') continue;
    ll tmp = i;
    sum -= (str[i] - '0');
    ans += ((('9' - str[i]) + 1) * kk);
    str[i] = '0';
    while (str[tmp - 1] == '9') {
      tmp--;
      sum -= 9;
      str[tmp] = '0';
    }
    str[tmp - 1] = (str[tmp - 1] + 1);
    sum++;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll t;
  cin >> t;
  for (ll i = 0; i < (ll)t; i++) {
    solve();
  }
  return 0;
}
