#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
void solve() {
  long long int a, b;
  cin >> a >> b;
  long long int p = a % b;
  if (p == 0)
    cout << 0 << "\n";
  else
    cout << b - p << "\n";
}
