#include <bits/stdc++.h>
int main() {
  long long int t, a, b, i, count;
  scanf("%lld", &t);
  for (i = 0; i < t; i++) {
    scanf("%lld %lld", &a, &b);
    count = 0;
    if (a > b) {
      if (a % b == 0) {
        printf("%lld\n", a % b);
      } else {
        b = ((a / b) + 1) * b;
        printf("%lld\n", b - a);
      }
    } else
      printf("%lld\n", b - a);
  }
  return 0;
}
