#include <bits/stdc++.h>
using namespace std;
long long sum_of_digits(long long n) {
  long long res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  long long s;
  cin >> s;
  long long moves = 0;
  int exp = 1;
  while (sum_of_digits(n) > s) {
    long long power_10 = pow(10, exp);
    long long moves_taken = power_10 - n % power_10;
    moves += moves_taken;
    n += moves_taken;
    exp++;
  }
  cout << moves << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
