#include <bits/stdc++.h>
using namespace std;
long long sumdig(long long n) {
  long long sum = 0;
  while (n) {
    sum += n % 10;
    n = n / 10;
  }
  return sum;
}
long long numdig(long long n) {
  long long num = 0;
  while (n) {
    n = n / 10;
    num += 1;
  }
  return num;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    if (sumdig(n) <= s) {
      cout << 0 << '\n';
      continue;
    }
    long long temp = pow(10ll, (numdig(n)));
    long long ans = temp - n;
    long long dig = 1;
    long long moves = 0;
    long long flag = 1;
    while (true) {
      if (n % 10 == 0) {
        n = n / 10;
        dig += 1;
      } else {
        moves += pow(10ll, dig - 1ll) * (10ll - (n % 10ll));
        long long x = numdig(n);
        n += 10ll - (n % 10ll);
        if (numdig(n) > x) {
          flag = 0;
          break;
        }
        if (sumdig(n) <= s) {
          break;
        }
      }
    }
    if (flag) {
      cout << min(ans, moves) << "\n";
    } else {
      cout << ans << "\n";
    }
  }
  return 0;
}
