#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    long long int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void judge() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  judge();
  int T;
  cin >> T;
  for (int tc = 1; tc <= T; tc++) {
    long long int a, b;
    cin >> a >> b;
    cout << (long long int)ceil(double(a) / (double)b) * b - a << "\n";
  }
  return 0;
}
