#include <bits/stdc++.h>
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b, x = 0;
    scanf("%d%d", &a, &b);
    if (a % b != 0) {
      x = b - (a % b);
    }
    printf("%d\n", x);
  }
}
