#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(8);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, s;
    cin >> n >> s;
    long long int n1 = n;
    vector<long long int> v;
    while (n1) {
      v.push_back(n1 % 10);
      n1 /= 10;
    }
    long long int sz = v.size();
    long long int sum = 0, c = 0;
    for (int i = 0; i < sz; i++) {
      sum += v[i];
    }
    if (sum <= s) {
      cout << 0 << "\n";
    } else {
      bool b = 0;
      for (int i = 0; i < sz - 1; i++) {
        sum -= v[i];
        sum += 1;
        v[i] = 0;
        v[i + 1] += 1;
        c++;
        if (sum <= s) {
          b = 1;
          break;
        }
      }
      if (!b) {
        v[sz - 1] = 0;
        v.push_back(1);
        sz++;
      }
      long long int r = 0, p = 1;
      for (int i = 0; i < sz; i++) {
        r += v[i] * p;
        p *= 10;
      }
      cout << r - n << "\n";
    }
  }
  return 0;
}
