#include <bits/stdc++.h>
int tcase, m;
long long n;
int gao(long long x) {
  int ret = 0;
  for (; x; x /= 10) ret += x % 10;
  return ret;
}
int main() {
  scanf("%d", &tcase);
  while (tcase--) {
    scanf("%lld%d", &n, &m);
    if (gao(n) <= m) {
      printf("0\n");
      continue;
    }
    long long x = 10;
    while (gao(n + (x - n % x)) > m) x *= 10;
    printf("%lld\n", x - n % x);
  }
  return 0;
}
