#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int k;
    cin >> k;
    long long int i = 0, sum = 0, sumi = 0;
    for (long long int l = 0; l < s.length(); l++) sumi += s[l] - 48;
    ;
    if (sumi <= k) {
      cout << 0 << endl;
      continue;
    }
    while (i < s.length()) {
      sum += (s[i] - 48);
      if (sum >= k) {
        break;
      }
      i++;
    }
    if (i == (s.length() - 1) && sum == k) {
      cout << 0 << endl;
      continue;
    }
    if (i == s.length()) {
      cout << 0 << endl;
      continue;
    }
    string t = "";
    t += '1';
    for (long long int j = i; j < s.length(); j++) {
      t += '0';
    }
    string c = s.substr(i);
    long long int z = stoll(t);
    long long int p = stoll(c);
    long long int ans = z - p;
    cout << ans << endl;
  }
}
