#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, i, j, k, l, p, q, r, s, t, n, m;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &n, &s);
    vector<long long int> vec, vec1;
    l = n;
    k = 0;
    d = 0;
    b = 1;
    while (n != 0) {
      vec.push_back(n % 10);
      k += n % 10;
      n = n / 10;
    }
    if (k <= s)
      printf("0\n");
    else {
      r = 0;
      for (i = 0; i < vec.size(); i++) {
        vec1.push_back(0);
        if (i == 0) {
          if (vec[i] == 0) continue;
          k -= (vec[i] - 1);
          r = 1;
        } else {
          if (vec[i] == 0) continue;
          if (r == 0) {
            k -= (vec[i] - 1);
            r = 1;
          } else
            k -= vec[i];
        }
        if (k <= s) break;
      }
      if (i == vec.size() - 1) {
        vec1.push_back(1);
        m = 0;
        b = 1;
        for (j = 0; j < vec1.size(); j++) {
          m += b * vec1[j];
          b = b * 10;
        }
      } else {
        if (vec[i + 1] == 9)
          vec1.push_back(0);
        else
          vec1.push_back(vec[i + 1] + 1);
        if (vec[i + 1] == 9)
          r = 1;
        else
          r = 0;
        for (j = i + 2; j < vec.size(); j++) {
          if (r == 1) {
            if (vec[j] == 9)
              vec1.push_back(0);
            else
              vec1.push_back(vec[j] + 1);
          } else
            vec1.push_back(vec[j]);
          if (vec[j] != 9) r = 0;
        }
        if (r == 1) vec1.push_back(1);
        m = 0;
        b = 1;
        for (j = 0; j < vec1.size(); j++) {
          m += b * vec1[j];
          b = b * 10;
        }
      }
      printf("%lld\n", m - l);
    }
  }
  return 0;
}
