#include <bits/stdc++.h>
using namespace std;
int sum(long long a) {
  long long res = 0;
  while (a > 0) {
    res += a % 10;
    a /= 10;
  }
  return res;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long n = 0;
    if (sum(a) <= b) {
      cout << 0 << "\n";
      continue;
    }
    long long h = 1;
    for (int i = 0; i < 18; i++) {
      int x = (a / h) % 10;
      long long add = h * ((10 - x) % 10);
      a += add;
      n += add;
      if (sum(a) <= b) {
        break;
      }
      h *= 10;
    }
    cout << n << endl;
  }
  return 0;
}
