#include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
long long int sum(long long int n) {
  long long int s = 0;
  while (n > 0) s += n % 10, n = n / 10;
  return s;
}
void solve() {
  long long int n, s;
  cin >> n >> s;
  long long int m = n;
  long long int power = 1;
  while (sum(m) > s) {
    power = power * 10;
    if (n % power == 0) continue;
    m = n + (power - n % power);
  }
  cout << m - n << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
