#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, a, b, ans;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    long long int k = a % b;
    if (k == 0)
      ans = 0;
    else
      ans = b - k;
    cout << ans << endl;
  }
  return 0;
}
