#include <bits/stdc++.h>
long long a, b, t, move;
int main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &a, &b);
    int tmp = a % b;
    if (tmp == 0) {
      printf("0\n");
    } else
      printf("%lld\n", b - tmp);
  }
}
