#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    if (a % b == 0) {
      cout << 0 << "\n";
    } else {
      long long int g = a / b;
      long long int ans = (b * (g + 1) - a);
      cout << ans << "\n";
    }
  }
  return 0;
}
