#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    if (n % m == 0) {
      cout << 0 << "\n";
      continue;
    }
    cout << m - (n % m) << "\n";
  }
  return 0;
}
