#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    vector<int> d;
    long long temp = n;
    int sum = 0;
    while (temp > 0) {
      int x = temp % 10;
      sum += x;
      d.push_back(x);
      temp /= 10;
    }
    if (sum <= s) {
      cout << 0 << '\n';
      continue;
    }
    long long ans = 0;
    int i = 0;
    while (sum > s - 1 && i < d.size()) {
      sum -= d[i];
      i++;
    }
    ans = (long long)pow(10, i);
    long long r = n % ans;
    ans -= r;
    cout << ans << '\n';
  }
}
