#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int digitSum(long long int n) {
  long long int sum = 0;
  while (n) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}
int main() {
  int t;
  long long int n, s, d, a, sum, i;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    sum = digitSum(n);
    if (sum <= s)
      cout << "0\n";
    else {
      a = 1;
      sum = 0;
      for (i = 1; i <= 18; i++) {
        d = (n / a) % 10;
        d = a * ((10 - d) % 10);
        n += d;
        sum += d;
        if (digitSum(n) <= s) break;
        a *= 10;
      }
      cout << sum << '\n';
    }
  }
  return 0;
}
