#include <bits/stdc++.h>
int main() {
  int A, B;
  int i, N, aux;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &A, &B);
    aux = A % B;
    if (aux != 0) {
      aux = B - aux;
    }
    printf("%d\n", aux);
  }
  return 0;
}
