#include <bits/stdc++.h>
using namespace std;
long long sum(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    long long n;
    int s;
    cin >> n >> s;
    long long ans = 0ll;
    if (sum(n) <= s) {
      cout << 0 << endl;
      continue;
    }
    long long power = 1ll;
    for (int i = 0; i < 18; i++) {
      int digit = (n / power) % 10;
      long long add = power * ((10 - digit) % 10);
      n += add;
      ans += add;
      if (sum(n) <= s) break;
      power *= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
