#include <bits/stdc++.h>
using namespace std;
void solve() {
  long double a, b;
  cin >> a >> b;
  if (fmod(a, b) == 0)
    cout << 0 << '\n';
  else
    cout << (long long)abs(a - (floor(a / b) + 1) * b) << '\n';
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
