#include <bits/stdc++.h>
using namespace std;
void func() {
  int n, m;
  cin >> n >> m;
  if (n % m == 0) {
    cout << 0 << "\n";
    return;
  } else {
    cout << m - (n % m) << "\n";
    return;
  }
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    func();
  }
  return 0;
}
