#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long int a, b, i = 0;
    int c = 0;
    scanf("%lld%lld", &a, &b);
    if (a % b == 0) {
      printf("%d\n", i);
      continue;
    }
    c = ((float)a / b) + 1;
    i = (c * b) - a;
    printf("%d\n", i);
  }
}
