#include <bits/stdc++.h>
using namespace std;
long long int arr[1000000], n, m;
int sum(long long int num) {
  int s = 0;
  while (num > 0) {
    s += (num % 10);
    num /= 10;
  }
  return s;
}
int main() {
  long long int t, i, j, k, r, c, cc, mn, g, a, b, l = 1, li, id = 1;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (sum(n) <= k)
      cout << 0 << endl;
    else {
      long long int ans = 0, p = 1, np = n;
      for (i = 0; i < 18; i++) {
        a = (10 - ((n / p) % 10)) % 10;
        n += (a * p);
        if (sum(n) <= k) break;
        p *= 10;
      }
      cout << n - np << endl;
    }
  }
  return 0;
}
