#include <bits/stdc++.h>
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 1000000007;
    }
    b >>= 1;
    x *= x;
    x %= 1000000007;
  }
  return p % 1000000007;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int tc;
  cin >> tc;
  for (long long int number = 1; number <= tc; number++) {
    long long int a, b;
    cin >> a >> b;
    if (a % b == 0)
      cout << 0 << "\n";
    else
      cout << (b - a % b) << "\n";
  }
  return 0;
}
