#include <bits/stdc++.h>
using namespace std;
long long int sum_return(long long int n) {
  long long int ans = 0;
  while (n) {
    ans += (n % 10);
    n = n / 10;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, s;
    cin >> n >> s;
    if (sum_return(n) <= s) {
      cout << "0\n";
    } else {
      long long int i = 1;
      long long int d = 1;
      long long int temp = n;
      while (sum_return(n) > s) {
        n = n + ((10 - ((n / d) % 10)) * i);
        d = d * 10;
        i = i * 10;
      }
      cout << n - temp << "\n";
    }
  }
  return 0;
}
