#include <bits/stdc++.h>
using namespace std;
long long T, n, s, k;
long long ssum(long long k) {
  long long tot = 0;
  while (k) {
    tot += k % 10;
    k /= 10;
  }
  return tot;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> s;
    k = 0;
    int now = ssum(n);
    if (now <= s) {
      cout << 0 << endl;
      continue;
    } else {
      long long tot = 1;
      while (now > s) {
        tot *= 10;
        if (!(n % tot)) continue;
        k += tot - (n % tot);
        n += tot - (n % tot);
        now = ssum(n);
      }
      cout << k << endl;
    }
  }
  return 0;
}
