#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    unsigned long long n;
    int s;
    cin >> n >> s;
    unsigned long long ans = 0;
    vector<int> vec(65, 0);
    int p = 0;
    while (n) {
      vec[p] = n % (unsigned long long)10;
      n /= (unsigned long long)10;
      p++;
    }
    int sum = 0;
    for (int i = 0; i < 65; i++) sum += vec[i];
    p = 0;
    while (sum > s) {
      if (vec[p] == 0) {
        p++;
        continue;
      }
      ans += (10 - vec[p]) * (unsigned long long)pow(10, p);
      sum -= vec[p];
      vec[p] = 0;
      int pn = p + 1;
      while (vec[pn] == 9) {
        sum -= vec[pn];
        vec[pn] = 0;
        pn++;
      }
      vec[pn]++;
      sum++;
      p = pn;
    }
    cout << ans << "\n";
  }
  return 0;
}
