#include <bits/stdc++.h>
using namespace std;
int t;
long long n, s;
int gao(long long num) {
  int res = 0;
  while (num) {
    res += num % 10;
    num /= 10;
  }
  return res;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &n, &s);
    long long ans = 0;
    for (int i = 1; i <= 19; i++) {
      if (gao(n) <= s) {
        break;
      }
      long long tmp = n, bit = 1;
      for (int j = 1; j <= i; j++) bit *= 10;
      n = n / bit * bit + bit;
      ans += n - tmp;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
