#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    long long cnt = 0, x = n;
    while (x) {
      cnt += x % 10;
      x /= 10;
    }
    long long ans = 0, now = 1;
    while (1) {
      if (cnt <= s) {
        cout << ans << endl;
        break;
      }
      long long p = n % 10;
      if (!p) p = 10;
      ans += (10 - p) * now;
      n += 10 - p;
      n /= 10;
      x = n;
      cnt = 0;
      while (x) {
        cnt += x % 10;
        x /= 10;
      }
      now *= 10;
    }
  }
  return 0;
}
