#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
long long getDigSum(long long x) {
  long long sum = 0;
  while (x) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    long long n_ = n, i = 1;
    while (getDigSum(n_) > s) {
      long long of = pow(10, i);
      n_ += (of - (n_ % of));
      i++;
    }
    cout << n_ - n << endl;
  }
  return 0;
}
