#include <bits/stdc++.h>
using namespace std;
int digitSum(long long n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie();
  iostream::sync_with_stdio(0);
  int t = 0;
  cin >> t;
  while (t--) {
    long long n;
    int s;
    cin >> n >> s;
    if (digitSum(n) <= s) {
      cout << 0 << endl;
      continue;
    }
    long long pos = 1;
    long long ans = 0;
    for (int i = 0; i < 18; i++) {
      int digit = (n / pos) % 10;
      long long add = pos * ((10 - digit) % 10);
      ans += add;
      n += add;
      if (digitSum(n) <= s) {
        break;
      }
      pos *= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
