#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
long long nxt;
bool Check(long long s) {
  long long ret = 0;
  while (s) {
    ret += (s % 10);
    if (ret > m) return false;
    s /= 10;
  }
  return true;
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    nxt = 1;
    long long Copy = n;
    while (!Check(n)) {
      n = (n + nxt - 1) / nxt * nxt;
      nxt *= 10;
    }
    cout << n - Copy << endl;
  }
  return 0;
}
