#include <bits/stdc++.h>
int main(void) {
  int t, s, sum;
  uint64_t n, moves, copy;
  scanf("%i", &t);
  for (; t; t--) {
    scanf("%llu %i", &n, &s);
    moves = 0;
    sum = 0;
    copy = n;
    while (copy) {
      sum += copy % 10;
      copy /= 10;
    }
    copy = n;
    if (sum <= s) {
      printf("%llu\n", moves);
      continue;
    }
    sum++;
    int i;
    for (i = 0; sum > s; i++) {
      sum -= copy % 10;
      copy /= 10;
    }
    copy++;
    for (; i; --i) {
      copy *= 10;
    }
    moves = copy - n;
    printf("%llu\n", moves);
  }
}
