#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long a, b;
    cin >> a >> b;
    if (a <= b) {
      cout << b - a << '\n';
      continue;
    }
    if (a % b == 0) {
      cout << "0\n";
      continue;
    }
    long long c = a - a % b;
    cout << b - (a - c) << '\n';
  }
  return 0;
}
