#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, s = 0, a, b, v = 0, d;
  cin >> t;
  for (int i = 0; i < t; i++) {
    s = 0;
    cin >> a >> b;
    if (a % b == 0)
      cout << s << endl;
    else {
      v = a / b;
      v++;
      d = b * v;
      s = d - a;
      cout << s << endl;
    }
  }
  return 0;
}
