#include <bits/stdc++.h>
int main() {
  unsigned int t;
  std::cin >> t;
  for (unsigned int i = 0; i < t; ++i) {
    unsigned int a, b;
    std::cin >> a >> b;
    unsigned int c = (b - a % b) % b;
    std::cout << c << std::endl;
  }
  return 0;
}
